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/public-api/object/type-registry-helper.h>
28 #include <dali/integration-api/adaptors/adaptor.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
34 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
35 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
36 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
37 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
38 #include <dali-toolkit/internal/text/rendering/text-backend.h>
39 #include <dali-toolkit/internal/text/text-effects-style.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
41 #include <dali-toolkit/internal/text/text-view.h>
42 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 using namespace Dali::Toolkit::Text;
55 namespace // unnamed namespace
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
62 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
63 } // unnamed namespace
68 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
70 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
71 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
72 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
74 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
76 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
78 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
79 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
80 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
82 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
87 return Toolkit::TextField::New();
90 // Setup properties, signals and actions using the type-registry.
91 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
138 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
139 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
146 DALI_TYPE_REGISTRATION_END()
150 Toolkit::TextField TextField::New()
152 // Create the implementation, temporarily owned by this handle on stack
153 IntrusivePtr< TextField > impl = new TextField();
155 // Pass ownership to CustomActor handle
156 Toolkit::TextField handle( *impl );
158 // Second-phase init of the implementation
159 // This can only be done after the CustomActor connection has been made...
165 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
167 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
169 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
174 TextField& impl( GetImpl( textField ) );
178 case Toolkit::TextField::Property::RENDERING_BACKEND:
180 int backend = value.Get< int >();
181 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
183 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
184 if( Text::RENDERING_VECTOR_BASED == backend )
186 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
189 if( impl.mRenderingBackend != backend )
191 impl.mRenderingBackend = backend;
192 impl.mRenderer.Reset();
194 if( impl.mController )
196 // When using the vector-based rendering, the size of the GLyphs are different
197 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
198 impl.mController->SetGlyphType( glyphType );
203 case Toolkit::TextField::Property::TEXT:
205 if( impl.mController )
207 const std::string& text = value.Get< std::string >();
208 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
210 impl.mController->SetText( text );
214 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
216 if( impl.mController )
218 const std::string& text = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
221 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
225 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
227 if( impl.mController )
229 const std::string& text = value.Get< std::string >();
230 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
232 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
236 case Toolkit::TextField::Property::FONT_FAMILY:
238 if( impl.mController )
240 const std::string& fontFamily = value.Get< std::string >();
241 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
242 impl.mController->SetDefaultFontFamily( fontFamily );
246 case Toolkit::TextField::Property::FONT_STYLE:
248 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
251 case Toolkit::TextField::Property::POINT_SIZE:
253 if( impl.mController )
255 const float pointSize = value.Get< float >();
256 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
258 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
260 impl.mController->SetDefaultPointSize( pointSize );
265 case Toolkit::TextField::Property::MAX_LENGTH:
267 if( impl.mController )
269 const int max = value.Get< int >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
272 impl.mController->SetMaximumNumberOfCharacters( max );
276 case Toolkit::TextField::Property::EXCEED_POLICY:
278 impl.mExceedPolicy = value.Get<int>();
280 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
282 impl.EnableClipping();
286 UnparentAndReset( impl.mStencil );
288 impl.RequestTextRelayout();
291 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
293 if( impl.mController )
295 const std::string& alignStr = value.Get< std::string >();
296 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
298 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
299 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
300 HORIZONTAL_ALIGNMENT_STRING_TABLE,
301 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
304 impl.mController->SetHorizontalAlignment( alignment );
309 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
311 if( impl.mController )
313 const std::string& alignStr = value.Get< std::string >();
314 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
316 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
317 if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
318 VERTICAL_ALIGNMENT_STRING_TABLE,
319 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
322 impl.mController->SetVerticalAlignment( alignment );
327 case Toolkit::TextField::Property::TEXT_COLOR:
329 if( impl.mController )
331 const Vector4& textColor = value.Get< Vector4 >();
332 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 );
334 if( impl.mController->GetDefaultColor() != textColor )
336 impl.mController->SetDefaultColor( textColor );
337 impl.mController->SetInputColor( textColor );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
345 if( impl.mController )
347 const Vector4& textColor = value.Get< Vector4 >();
348 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 );
350 if( impl.mController->GetPlaceholderTextColor() != textColor )
352 impl.mController->SetPlaceholderTextColor( textColor );
353 impl.mRenderer.Reset();
358 case Toolkit::TextField::Property::SHADOW_OFFSET:
360 if( impl.mController )
362 const Vector2& shadowOffset = value.Get< Vector2 >();
363 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
365 if ( impl.mController->GetShadowOffset() != shadowOffset )
367 impl.mController->SetShadowOffset( shadowOffset );
368 impl.mRenderer.Reset();
373 case Toolkit::TextField::Property::SHADOW_COLOR:
375 if( impl.mController )
377 const Vector4& shadowColor = value.Get< Vector4 >();
378 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 );
380 if ( impl.mController->GetShadowColor() != shadowColor )
382 impl.mController->SetShadowColor( shadowColor );
383 impl.mRenderer.Reset();
388 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
390 if( impl.mDecorator )
392 const Vector4& color = value.Get< Vector4 >();
393 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 );
395 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
396 impl.RequestTextRelayout();
400 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
402 if( impl.mDecorator )
404 const Vector4& color = value.Get< Vector4 >();
405 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 );
407 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
408 impl.RequestTextRelayout();
412 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
414 if( impl.mController )
416 const bool enable = value.Get< bool >();
417 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
419 impl.mController->SetEnableCursorBlink( enable );
420 impl.RequestTextRelayout();
424 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
426 if( impl.mDecorator )
428 const float interval = value.Get< float >();
429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
431 impl.mDecorator->SetCursorBlinkInterval( interval );
435 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
437 if( impl.mDecorator )
439 const float duration = value.Get< float >();
440 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
442 impl.mDecorator->SetCursorBlinkDuration( duration );
446 case Toolkit::TextField::Property::CURSOR_WIDTH:
448 if( impl.mDecorator )
450 const int width = value.Get< int >();
451 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
453 impl.mDecorator->SetCursorWidth( width );
454 impl.mController->GetLayoutEngine().SetCursorWidth( width );
458 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
460 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
463 if( impl.mDecorator )
465 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
466 impl.RequestTextRelayout();
470 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
472 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
473 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
475 if( impl.mDecorator )
477 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
478 impl.RequestTextRelayout();
482 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
484 const float threshold = value.Get< float >();
485 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
487 if( impl.mDecorator )
489 impl.mDecorator->SetScrollThreshold( threshold );
493 case Toolkit::TextField::Property::SCROLL_SPEED:
495 const float speed = value.Get< float >();
496 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
498 if( impl.mDecorator )
500 impl.mDecorator->SetScrollSpeed( speed );
504 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
506 const Image image = Scripting::NewImage( value );
508 if( impl.mDecorator && image )
510 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
511 impl.RequestTextRelayout();
515 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
517 const Image image = Scripting::NewImage( value );
519 if( impl.mDecorator && image )
521 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
522 impl.RequestTextRelayout();
526 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
528 const Image image = Scripting::NewImage( value );
530 if( impl.mDecorator && image )
532 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
533 impl.RequestTextRelayout();
537 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
539 const Image image = Scripting::NewImage( value );
541 if( impl.mDecorator && image )
543 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
544 impl.RequestTextRelayout();
548 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
550 const Image image = Scripting::NewImage( value );
552 if( impl.mDecorator && image )
554 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
555 impl.RequestTextRelayout();
559 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
561 const Image image = Scripting::NewImage( value );
563 if( impl.mDecorator && image )
565 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
566 impl.RequestTextRelayout();
570 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
572 const Vector4 color = value.Get< Vector4 >();
573 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 );
575 if( impl.mDecorator )
577 impl.mDecorator->SetHighlightColor( color );
578 impl.RequestTextRelayout();
582 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
584 if( impl.mDecorator )
586 const Rect<int> box = value.Get< Rect<int> >();
587 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 );
589 impl.mDecorator->SetBoundingBox( box );
590 impl.RequestTextRelayout();
594 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
596 const Property::Map* map = value.GetMap();
599 impl.mInputMethodOptions.ApplyProperty( *map );
601 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
603 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
604 if (control == textField)
606 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
610 case Toolkit::TextField::Property::INPUT_COLOR:
612 if( impl.mController )
614 const Vector4 inputColor = value.Get< Vector4 >();
615 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 );
617 impl.mController->SetInputColor( inputColor );
621 case Toolkit::TextField::Property::ENABLE_MARKUP:
623 if( impl.mController )
625 const bool enableMarkup = value.Get<bool>();
626 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
628 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
632 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
634 if( impl.mController )
636 const std::string& fontFamily = value.Get< std::string >();
637 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
638 impl.mController->SetInputFontFamily( fontFamily );
642 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
644 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
647 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
649 if( impl.mController )
651 const float pointSize = value.Get< float >();
652 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
653 impl.mController->SetInputFontPointSize( pointSize );
657 case Toolkit::TextField::Property::UNDERLINE:
659 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
662 impl.mRenderer.Reset();
666 case Toolkit::TextField::Property::INPUT_UNDERLINE:
668 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
671 impl.mRenderer.Reset();
675 case Toolkit::TextField::Property::SHADOW:
677 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
680 impl.mRenderer.Reset();
684 case Toolkit::TextField::Property::INPUT_SHADOW:
686 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
689 impl.mRenderer.Reset();
693 case Toolkit::TextField::Property::EMBOSS:
695 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
698 impl.mRenderer.Reset();
702 case Toolkit::TextField::Property::INPUT_EMBOSS:
704 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
707 impl.mRenderer.Reset();
711 case Toolkit::TextField::Property::OUTLINE:
713 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
716 impl.mRenderer.Reset();
720 case Toolkit::TextField::Property::INPUT_OUTLINE:
722 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
725 impl.mRenderer.Reset();
729 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
731 const Property::Map* map = value.GetMap();
734 impl.mController->SetHiddenInputOption(*map);
742 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
744 Property::Value value;
746 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
750 TextField& impl( GetImpl( textField ) );
754 case Toolkit::TextField::Property::RENDERING_BACKEND:
756 value = impl.mRenderingBackend;
759 case Toolkit::TextField::Property::TEXT:
761 if( impl.mController )
764 impl.mController->GetText( text );
765 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
770 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
772 if( impl.mController )
775 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
780 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
782 if( impl.mController )
785 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
790 case Toolkit::TextField::Property::FONT_FAMILY:
792 if( impl.mController )
794 value = impl.mController->GetDefaultFontFamily();
798 case Toolkit::TextField::Property::FONT_STYLE:
800 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
803 case Toolkit::TextField::Property::POINT_SIZE:
805 if( impl.mController )
807 value = impl.mController->GetDefaultPointSize();
811 case Toolkit::TextField::Property::MAX_LENGTH:
813 if( impl.mController )
815 value = impl.mController->GetMaximumNumberOfCharacters();
819 case Toolkit::TextField::Property::EXCEED_POLICY:
821 value = impl.mExceedPolicy;
824 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
826 if( impl.mController )
828 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
829 HORIZONTAL_ALIGNMENT_STRING_TABLE,
830 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
833 value = std::string( name );
838 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
840 if( impl.mController )
842 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
843 VERTICAL_ALIGNMENT_STRING_TABLE,
844 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
847 value = std::string( name );
852 case Toolkit::TextField::Property::TEXT_COLOR:
854 if ( impl.mController )
856 value = impl.mController->GetDefaultColor();
860 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
862 if ( impl.mController )
864 value = impl.mController->GetPlaceholderTextColor();
868 case Toolkit::TextField::Property::SHADOW_OFFSET:
870 if ( impl.mController )
872 value = impl.mController->GetShadowOffset();
876 case Toolkit::TextField::Property::SHADOW_COLOR:
878 if ( impl.mController )
880 value = impl.mController->GetShadowColor();
884 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
886 if( impl.mDecorator )
888 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
892 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
894 if( impl.mDecorator )
896 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
900 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
902 value = impl.mController->GetEnableCursorBlink();
905 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
907 if( impl.mDecorator )
909 value = impl.mDecorator->GetCursorBlinkInterval();
913 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
915 if( impl.mDecorator )
917 value = impl.mDecorator->GetCursorBlinkDuration();
921 case Toolkit::TextField::Property::CURSOR_WIDTH:
923 if( impl.mDecorator )
925 value = impl.mDecorator->GetCursorWidth();
929 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
931 if( impl.mDecorator )
933 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
936 value = image.GetUrl();
941 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
943 if( impl.mDecorator )
945 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
948 value = image.GetUrl();
953 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
955 if( impl.mDecorator )
957 value = impl.mDecorator->GetScrollThreshold();
961 case Toolkit::TextField::Property::SCROLL_SPEED:
963 if( impl.mDecorator )
965 value = impl.mDecorator->GetScrollSpeed();
969 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
971 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
974 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
976 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
979 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
981 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
984 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
986 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
989 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
991 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
994 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
996 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
999 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1001 if( impl.mDecorator )
1003 value = impl.mDecorator->GetHighlightColor();
1007 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1009 if( impl.mDecorator )
1011 Rect<int> boundingBox;
1012 impl.mDecorator->GetBoundingBox( boundingBox );
1013 value = boundingBox;
1017 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1020 impl.mInputMethodOptions.RetrieveProperty( map );
1024 case Toolkit::TextField::Property::INPUT_COLOR:
1026 if( impl.mController )
1028 value = impl.mController->GetInputColor();
1032 case Toolkit::TextField::Property::ENABLE_MARKUP:
1034 if( impl.mController )
1036 value = impl.mController->IsMarkupProcessorEnabled();
1040 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1042 if( impl.mController )
1044 value = impl.mController->GetInputFontFamily();
1048 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1050 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1053 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1055 if( impl.mController )
1057 value = impl.mController->GetInputFontPointSize();
1061 case Toolkit::TextField::Property::UNDERLINE:
1063 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1066 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1068 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1071 case Toolkit::TextField::Property::SHADOW:
1073 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1076 case Toolkit::TextField::Property::INPUT_SHADOW:
1078 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1081 case Toolkit::TextField::Property::EMBOSS:
1083 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1086 case Toolkit::TextField::Property::INPUT_EMBOSS:
1088 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1091 case Toolkit::TextField::Property::OUTLINE:
1093 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1096 case Toolkit::TextField::Property::INPUT_OUTLINE:
1098 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1101 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
1104 impl.mController->GetHiddenInputOption(map);
1114 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1116 Dali::BaseHandle handle( object );
1118 bool connected( true );
1119 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1121 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1123 field.TextChangedSignal().Connect( tracker, functor );
1125 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1127 field.MaxLengthReachedSignal().Connect( tracker, functor );
1129 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1131 field.InputStyleChangedSignal().Connect( tracker, functor );
1135 // signalName does not match any signal
1142 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1144 return mTextChangedSignal;
1147 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1149 return mMaxLengthReachedSignal;
1152 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1154 return mInputStyleChangedSignal;
1157 void TextField::OnInitialize()
1159 Actor self = Self();
1161 mController = Text::Controller::New( this, this );
1163 // When using the vector-based rendering, the size of the GLyphs are different
1164 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1165 mController->SetGlyphType( glyphType );
1167 mDecorator = Text::Decorator::New( *mController,
1170 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1172 // Enables the text input.
1173 mController->EnableTextInput( mDecorator );
1175 // Enables the horizontal scrolling after the text input has been enabled.
1176 mController->SetHorizontalScrollEnabled( true );
1178 // Disables the vertical scrolling.
1179 mController->SetVerticalScrollEnabled( false );
1181 // Disable the smooth handle panning.
1182 mController->SetSmoothHandlePanEnabled( false );
1184 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1185 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1187 // Forward input events to controller
1188 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1189 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1191 mImfManager = ImfManager::Get();
1193 self.TouchSignal().Connect( this, &TextField::OnTouched );
1195 // Set BoundingBox to stage size if not already set.
1196 Rect<int> boundingBox;
1197 mDecorator->GetBoundingBox( boundingBox );
1199 if( boundingBox.IsEmpty() )
1201 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1202 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1205 // Flip vertically the 'left' selection handle
1206 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1208 // Fill-parent area by default
1209 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1210 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1211 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1213 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1219 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1221 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1225 case StyleChange::DEFAULT_FONT_CHANGE:
1227 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1228 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1229 // Property system did not set the font so should update it.
1230 mController->UpdateAfterFontChange( newFont );
1235 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1237 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1241 case StyleChange::THEME_CHANGE:
1243 // Nothing to do, let control base class handle this
1248 // Up call to Control
1249 Control::OnStyleChange( styleManager, change );
1252 Vector3 TextField::GetNaturalSize()
1254 return mController->GetNaturalSize();
1257 float TextField::GetHeightForWidth( float width )
1259 return mController->GetHeightForWidth( width );
1262 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1264 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1266 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1268 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1271 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1274 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1276 mDecorator->Relayout( size );
1281 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1284 RenderText( updateTextType );
1287 // The text-field emits signals when the input style changes. These changes of style are
1288 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1289 // can't be emitted during the size negotiation as the callbacks may update the UI.
1290 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1291 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1293 if( Adaptor::IsAvailable() )
1295 Adaptor& adaptor = Adaptor::Get();
1297 if( NULL == mIdleCallback )
1299 // @note: The callback manager takes the ownership of the callback object.
1300 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1301 adaptor.AddIdle( mIdleCallback );
1307 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1309 Actor renderableActor;
1311 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1315 renderableActor = mRenderer->Render( mController->GetView(),
1317 DepthIndex::CONTENT );
1320 if( renderableActor != mRenderableActor )
1322 UnparentAndReset( mRenderableActor );
1323 mRenderableActor = renderableActor;
1327 if( mRenderableActor )
1329 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1331 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1333 // Make sure the actors are parented correctly with/without clipping
1334 Actor self = mStencil ? mStencil : Self();
1336 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1337 endIt = mClippingDecorationActors.end();
1343 mClippingDecorationActors.clear();
1345 self.Add( mRenderableActor );
1349 void TextField::OnKeyInputFocusGained()
1351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1353 mImfManager.ApplyOptions( mInputMethodOptions );
1355 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1357 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1359 // Notify that the text editing start.
1360 mImfManager.Activate();
1362 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1363 mImfManager.SetRestoreAfterFocusLost( true );
1365 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1369 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1372 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1374 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1377 void TextField::OnKeyInputFocusLost()
1379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1381 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1382 // The text editing is finished. Therefore the imf manager don't have restore activation.
1383 mImfManager.SetRestoreAfterFocusLost( false );
1385 // Notify that the text editing finish.
1386 mImfManager.Deactivate();
1388 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1390 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1394 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1397 mController->KeyboardFocusLostEvent();
1399 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1402 void TextField::OnTap( const TapGesture& gesture )
1404 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1406 mImfManager.Activate();
1408 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1409 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1414 void TextField::OnPan( const PanGesture& gesture )
1416 mController->PanEvent( gesture.state, gesture.displacement );
1419 void TextField::OnLongPress( const LongPressGesture& gesture )
1421 mImfManager.Activate();
1423 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1428 bool TextField::OnKeyEvent( const KeyEvent& event )
1430 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1432 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1434 // Make sure ClearKeyInputFocus when only key is up
1435 if( event.state == KeyEvent::Up )
1437 ClearKeyInputFocus();
1443 return mController->KeyEvent( event );
1446 void TextField::RequestTextRelayout()
1451 void TextField::TextChanged()
1453 Dali::Toolkit::TextField handle( GetOwner() );
1454 mTextChangedSignal.Emit( handle );
1457 void TextField::MaxLengthReached()
1459 Dali::Toolkit::TextField handle( GetOwner() );
1460 mMaxLengthReachedSignal.Emit( handle );
1463 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1465 Dali::Toolkit::TextField handle( GetOwner() );
1467 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1469 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1471 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1473 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1475 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1477 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1479 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1481 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1483 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1485 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1487 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1489 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1491 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1493 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1495 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1497 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1499 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1501 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1503 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1505 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1507 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1510 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1513 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1519 mClippingDecorationActors.push_back( actor );
1523 Self().Add( actor );
1528 void TextField::OnStageConnect( Dali::Actor actor )
1530 if ( mHasBeenStaged )
1532 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1536 mHasBeenStaged = true;
1540 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1542 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1543 return mController->OnImfEvent( imfManager, imfEvent );
1546 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1550 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1555 Scripting::CreatePropertyMap( image, map );
1561 void TextField::EnableClipping()
1565 // Creates an extra control to be used as stencil buffer.
1566 mStencil = Control::New();
1567 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1568 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1570 // Creates a background visual. Even if the color is transparent it updates the stencil.
1571 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1572 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1573 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1575 // Enable the clipping property.
1576 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1577 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1579 Self().Add( mStencil );
1583 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1585 mController->PasteClipboardItemEvent();
1588 void TextField::KeyboardStatusChanged(bool keyboardShown)
1590 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1592 // Just hide the grab handle when keyboard is hidden.
1593 if (!keyboardShown )
1595 mController->KeyboardFocusLostEvent();
1599 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1603 void TextField::OnStageConnection( int depth )
1605 // Sets the depth to the visuals inside the text's decorator.
1606 mDecorator->SetTextDepth( depth );
1608 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1610 // Call the Control::OnStageConnection() to set the depth of the background.
1611 Control::OnStageConnection( depth );
1614 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1619 void TextField::OnIdleSignal()
1621 // Emits the change of input style signals.
1622 mController->ProcessInputStyleChangedSignals();
1624 // Set the pointer to null as the callback manager deletes the callback after execute it.
1625 mIdleCallback = NULL;
1628 TextField::TextField()
1629 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1630 mIdleCallback( NULL ),
1631 mAlignmentOffset( 0.f ),
1632 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1633 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1634 mHasBeenStaged( false )
1638 TextField::~TextField()
1640 UnparentAndReset( mStencil );
1642 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1644 Adaptor::Get().RemoveIdle( mIdleCallback );
1648 } // namespace Internal
1650 } // namespace Toolkit