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/public-api/object/type-registry-helper.h>
27 #include <dali/integration-api/adaptors/adaptor.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/text/rendering-backend.h>
32 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
35 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
36 #include <dali-toolkit/internal/text/rendering/text-backend.h>
37 #include <dali-toolkit/internal/text/text-effects-style.h>
38 #include <dali-toolkit/internal/text/text-font-style.h>
39 #include <dali-toolkit/internal/text/text-view.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 using namespace Dali::Toolkit::Text;
53 namespace // unnamed namespace
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
60 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
61 } // unnamed namespace
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
68 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
69 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
70 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
74 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
76 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
77 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
78 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
80 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
85 return Toolkit::TextField::New();
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
143 DALI_TYPE_REGISTRATION_END()
147 Toolkit::TextField TextField::New()
149 // Create the implementation, temporarily owned by this handle on stack
150 IntrusivePtr< TextField > impl = new TextField();
152 // Pass ownership to CustomActor handle
153 Toolkit::TextField handle( *impl );
155 // Second-phase init of the implementation
156 // This can only be done after the CustomActor connection has been made...
162 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
164 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
166 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
171 TextField& impl( GetImpl( textField ) );
175 case Toolkit::TextField::Property::RENDERING_BACKEND:
177 int backend = value.Get< int >();
178 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
180 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
181 if( Text::RENDERING_VECTOR_BASED == backend )
183 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
186 if( impl.mRenderingBackend != backend )
188 impl.mRenderingBackend = backend;
189 impl.mRenderer.Reset();
191 if( impl.mController )
193 // When using the vector-based rendering, the size of the GLyphs are different
194 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
195 impl.mController->SetGlyphType( glyphType );
200 case Toolkit::TextField::Property::TEXT:
202 if( impl.mController )
204 const std::string& text = value.Get< std::string >();
205 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
207 impl.mController->SetText( text );
211 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
213 if( impl.mController )
215 const std::string& text = value.Get< std::string >();
216 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
218 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
222 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
224 if( impl.mController )
226 const std::string& text = value.Get< std::string >();
227 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
229 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
233 case Toolkit::TextField::Property::FONT_FAMILY:
235 if( impl.mController )
237 const std::string& fontFamily = value.Get< std::string >();
238 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
239 impl.mController->SetDefaultFontFamily( fontFamily );
243 case Toolkit::TextField::Property::FONT_STYLE:
245 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
248 case Toolkit::TextField::Property::POINT_SIZE:
250 if( impl.mController )
252 const float pointSize = value.Get< float >();
253 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
255 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
257 impl.mController->SetDefaultPointSize( pointSize );
262 case Toolkit::TextField::Property::MAX_LENGTH:
264 if( impl.mController )
266 const int max = value.Get< int >();
267 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
269 impl.mController->SetMaximumNumberOfCharacters( max );
273 case Toolkit::TextField::Property::EXCEED_POLICY:
275 impl.mExceedPolicy = value.Get<int>();
277 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
279 impl.EnableClipping();
283 UnparentAndReset( impl.mStencil );
285 impl.RequestTextRelayout();
288 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
290 if( impl.mController )
292 const std::string& alignStr = value.Get< std::string >();
293 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
295 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
296 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
297 HORIZONTAL_ALIGNMENT_STRING_TABLE,
298 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
301 impl.mController->SetHorizontalAlignment( alignment );
306 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
308 if( impl.mController )
310 const std::string& alignStr = value.Get< std::string >();
311 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
313 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
314 if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
315 VERTICAL_ALIGNMENT_STRING_TABLE,
316 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
319 impl.mController->SetVerticalAlignment( alignment );
324 case Toolkit::TextField::Property::TEXT_COLOR:
326 if( impl.mController )
328 const Vector4& textColor = value.Get< Vector4 >();
329 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 );
331 if( impl.mController->GetDefaultColor() != textColor )
333 impl.mController->SetDefaultColor( textColor );
334 impl.mController->SetInputColor( textColor );
335 impl.mRenderer.Reset();
340 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
342 if( impl.mController )
344 const Vector4& textColor = value.Get< Vector4 >();
345 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 );
347 if( impl.mController->GetPlaceholderTextColor() != textColor )
349 impl.mController->SetPlaceholderTextColor( textColor );
350 impl.mRenderer.Reset();
355 case Toolkit::TextField::Property::SHADOW_OFFSET:
357 if( impl.mController )
359 const Vector2& shadowOffset = value.Get< Vector2 >();
360 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
362 if ( impl.mController->GetShadowOffset() != shadowOffset )
364 impl.mController->SetShadowOffset( shadowOffset );
365 impl.mRenderer.Reset();
370 case Toolkit::TextField::Property::SHADOW_COLOR:
372 if( impl.mController )
374 const Vector4& shadowColor = value.Get< Vector4 >();
375 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 );
377 if ( impl.mController->GetShadowColor() != shadowColor )
379 impl.mController->SetShadowColor( shadowColor );
380 impl.mRenderer.Reset();
385 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
387 if( impl.mDecorator )
389 const Vector4& color = value.Get< Vector4 >();
390 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 );
392 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
399 if( impl.mDecorator )
401 const Vector4& color = value.Get< Vector4 >();
402 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 );
404 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
405 impl.RequestTextRelayout();
409 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
411 if( impl.mController )
413 const bool enable = value.Get< bool >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
416 impl.mController->SetEnableCursorBlink( enable );
417 impl.RequestTextRelayout();
421 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
423 if( impl.mDecorator )
425 const float interval = value.Get< float >();
426 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
428 impl.mDecorator->SetCursorBlinkInterval( interval );
432 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
434 if( impl.mDecorator )
436 const float duration = value.Get< float >();
437 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
439 impl.mDecorator->SetCursorBlinkDuration( duration );
443 case Toolkit::TextField::Property::CURSOR_WIDTH:
445 if( impl.mDecorator )
447 const int width = value.Get< int >();
448 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
450 impl.mDecorator->SetCursorWidth( width );
451 impl.mController->GetLayoutEngine().SetCursorWidth( width );
455 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
457 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
460 if( impl.mDecorator )
462 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
463 impl.RequestTextRelayout();
467 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
469 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
472 if( impl.mDecorator )
474 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
475 impl.RequestTextRelayout();
479 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
481 const float threshold = value.Get< float >();
482 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
484 if( impl.mDecorator )
486 impl.mDecorator->SetScrollThreshold( threshold );
490 case Toolkit::TextField::Property::SCROLL_SPEED:
492 const float speed = value.Get< float >();
493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
495 if( impl.mDecorator )
497 impl.mDecorator->SetScrollSpeed( speed );
501 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
503 const Image image = Scripting::NewImage( value );
505 if( impl.mDecorator && image )
507 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
508 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
514 const Image image = Scripting::NewImage( value );
516 if( impl.mDecorator && image )
518 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
519 impl.RequestTextRelayout();
523 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
525 const Image image = Scripting::NewImage( value );
527 if( impl.mDecorator && image )
529 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
530 impl.RequestTextRelayout();
534 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
536 const Image image = Scripting::NewImage( value );
538 if( impl.mDecorator && image )
540 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
541 impl.RequestTextRelayout();
545 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
547 const Image image = Scripting::NewImage( value );
549 if( impl.mDecorator && image )
551 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
552 impl.RequestTextRelayout();
556 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
558 const Image image = Scripting::NewImage( value );
560 if( impl.mDecorator && image )
562 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
563 impl.RequestTextRelayout();
567 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
569 const Vector4 color = value.Get< Vector4 >();
570 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 );
572 if( impl.mDecorator )
574 impl.mDecorator->SetHighlightColor( color );
575 impl.RequestTextRelayout();
579 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
581 if( impl.mDecorator )
583 const Rect<int> box = value.Get< Rect<int> >();
584 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 );
586 impl.mDecorator->SetBoundingBox( box );
587 impl.RequestTextRelayout();
591 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
593 const Property::Map* map = value.GetMap();
596 impl.mInputMethodOptions.ApplyProperty( *map );
598 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
600 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
601 if (control == textField)
603 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
607 case Toolkit::TextField::Property::INPUT_COLOR:
609 if( impl.mController )
611 const Vector4 inputColor = value.Get< Vector4 >();
612 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 );
614 impl.mController->SetInputColor( inputColor );
618 case Toolkit::TextField::Property::ENABLE_MARKUP:
620 if( impl.mController )
622 const bool enableMarkup = value.Get<bool>();
623 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
625 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
629 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
631 if( impl.mController )
633 const std::string& fontFamily = value.Get< std::string >();
634 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
635 impl.mController->SetInputFontFamily( fontFamily );
639 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
641 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
644 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
646 if( impl.mController )
648 const float pointSize = value.Get< float >();
649 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
650 impl.mController->SetInputFontPointSize( pointSize );
654 case Toolkit::TextField::Property::UNDERLINE:
656 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
659 impl.mRenderer.Reset();
663 case Toolkit::TextField::Property::INPUT_UNDERLINE:
665 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
668 impl.mRenderer.Reset();
672 case Toolkit::TextField::Property::SHADOW:
674 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
677 impl.mRenderer.Reset();
681 case Toolkit::TextField::Property::INPUT_SHADOW:
683 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
686 impl.mRenderer.Reset();
690 case Toolkit::TextField::Property::EMBOSS:
692 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
695 impl.mRenderer.Reset();
699 case Toolkit::TextField::Property::INPUT_EMBOSS:
701 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
704 impl.mRenderer.Reset();
708 case Toolkit::TextField::Property::OUTLINE:
710 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
713 impl.mRenderer.Reset();
717 case Toolkit::TextField::Property::INPUT_OUTLINE:
719 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
722 impl.mRenderer.Reset();
730 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
732 Property::Value value;
734 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
738 TextField& impl( GetImpl( textField ) );
742 case Toolkit::TextField::Property::RENDERING_BACKEND:
744 value = impl.mRenderingBackend;
747 case Toolkit::TextField::Property::TEXT:
749 if( impl.mController )
752 impl.mController->GetText( text );
753 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
758 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
760 if( impl.mController )
763 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
768 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
770 if( impl.mController )
773 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
778 case Toolkit::TextField::Property::FONT_FAMILY:
780 if( impl.mController )
782 value = impl.mController->GetDefaultFontFamily();
786 case Toolkit::TextField::Property::FONT_STYLE:
788 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
791 case Toolkit::TextField::Property::POINT_SIZE:
793 if( impl.mController )
795 value = impl.mController->GetDefaultPointSize();
799 case Toolkit::TextField::Property::MAX_LENGTH:
801 if( impl.mController )
803 value = impl.mController->GetMaximumNumberOfCharacters();
807 case Toolkit::TextField::Property::EXCEED_POLICY:
809 value = impl.mExceedPolicy;
812 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
814 if( impl.mController )
816 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
817 HORIZONTAL_ALIGNMENT_STRING_TABLE,
818 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
821 value = std::string( name );
826 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
828 if( impl.mController )
830 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
831 VERTICAL_ALIGNMENT_STRING_TABLE,
832 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
835 value = std::string( name );
840 case Toolkit::TextField::Property::TEXT_COLOR:
842 if ( impl.mController )
844 value = impl.mController->GetDefaultColor();
848 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
850 if ( impl.mController )
852 value = impl.mController->GetPlaceholderTextColor();
856 case Toolkit::TextField::Property::SHADOW_OFFSET:
858 if ( impl.mController )
860 value = impl.mController->GetShadowOffset();
864 case Toolkit::TextField::Property::SHADOW_COLOR:
866 if ( impl.mController )
868 value = impl.mController->GetShadowColor();
872 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
874 if( impl.mDecorator )
876 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
880 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
882 if( impl.mDecorator )
884 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
888 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
890 value = impl.mController->GetEnableCursorBlink();
893 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
895 if( impl.mDecorator )
897 value = impl.mDecorator->GetCursorBlinkInterval();
901 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
903 if( impl.mDecorator )
905 value = impl.mDecorator->GetCursorBlinkDuration();
909 case Toolkit::TextField::Property::CURSOR_WIDTH:
911 if( impl.mDecorator )
913 value = impl.mDecorator->GetCursorWidth();
917 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
919 if( impl.mDecorator )
921 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
924 value = image.GetUrl();
929 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
931 if( impl.mDecorator )
933 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
936 value = image.GetUrl();
941 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
943 if( impl.mDecorator )
945 value = impl.mDecorator->GetScrollThreshold();
949 case Toolkit::TextField::Property::SCROLL_SPEED:
951 if( impl.mDecorator )
953 value = impl.mDecorator->GetScrollSpeed();
957 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
959 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
962 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
964 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
967 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
969 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
972 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
974 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
977 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
979 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
982 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
984 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
987 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
989 if( impl.mDecorator )
991 value = impl.mDecorator->GetHighlightColor();
995 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
997 if( impl.mDecorator )
999 Rect<int> boundingBox;
1000 impl.mDecorator->GetBoundingBox( boundingBox );
1001 value = boundingBox;
1005 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1008 impl.mInputMethodOptions.RetrieveProperty( map );
1012 case Toolkit::TextField::Property::INPUT_COLOR:
1014 if( impl.mController )
1016 value = impl.mController->GetInputColor();
1020 case Toolkit::TextField::Property::ENABLE_MARKUP:
1022 if( impl.mController )
1024 value = impl.mController->IsMarkupProcessorEnabled();
1028 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1030 if( impl.mController )
1032 value = impl.mController->GetInputFontFamily();
1036 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1038 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1041 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1043 if( impl.mController )
1045 value = impl.mController->GetInputFontPointSize();
1049 case Toolkit::TextField::Property::UNDERLINE:
1051 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1054 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1056 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1059 case Toolkit::TextField::Property::SHADOW:
1061 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1064 case Toolkit::TextField::Property::INPUT_SHADOW:
1066 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1069 case Toolkit::TextField::Property::EMBOSS:
1071 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1074 case Toolkit::TextField::Property::INPUT_EMBOSS:
1076 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1079 case Toolkit::TextField::Property::OUTLINE:
1081 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1084 case Toolkit::TextField::Property::INPUT_OUTLINE:
1086 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1095 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1097 Dali::BaseHandle handle( object );
1099 bool connected( true );
1100 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1102 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1104 field.TextChangedSignal().Connect( tracker, functor );
1106 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1108 field.MaxLengthReachedSignal().Connect( tracker, functor );
1110 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1112 field.InputStyleChangedSignal().Connect( tracker, functor );
1116 // signalName does not match any signal
1123 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1125 return mTextChangedSignal;
1128 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1130 return mMaxLengthReachedSignal;
1133 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1135 return mInputStyleChangedSignal;
1138 void TextField::OnInitialize()
1140 Actor self = Self();
1142 mController = Text::Controller::New( this, this );
1144 // When using the vector-based rendering, the size of the GLyphs are different
1145 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1146 mController->SetGlyphType( glyphType );
1148 mDecorator = Text::Decorator::New( *mController,
1151 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1153 // Enables the text input.
1154 mController->EnableTextInput( mDecorator );
1156 // Enables the horizontal scrolling after the text input has been enabled.
1157 mController->SetHorizontalScrollEnabled( true );
1159 // Disables the vertical scrolling.
1160 mController->SetVerticalScrollEnabled( false );
1162 // Disable the smooth handle panning.
1163 mController->SetSmoothHandlePanEnabled( false );
1165 // Forward input events to controller
1166 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1167 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1169 mImfManager = ImfManager::Get();
1171 self.TouchSignal().Connect( this, &TextField::OnTouched );
1173 // Set BoundingBox to stage size if not already set.
1174 Rect<int> boundingBox;
1175 mDecorator->GetBoundingBox( boundingBox );
1177 if( boundingBox.IsEmpty() )
1179 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1180 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1183 // Flip vertically the 'left' selection handle
1184 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1186 // Fill-parent area by default
1187 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1188 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1189 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1191 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1197 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1199 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1203 case StyleChange::DEFAULT_FONT_CHANGE:
1205 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1206 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1207 // Property system did not set the font so should update it.
1208 mController->UpdateAfterFontChange( newFont );
1212 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1214 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1217 case StyleChange::THEME_CHANGE:
1219 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1225 Vector3 TextField::GetNaturalSize()
1227 return mController->GetNaturalSize();
1230 float TextField::GetHeightForWidth( float width )
1232 return mController->GetHeightForWidth( width );
1235 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1237 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1239 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1241 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1244 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1247 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1249 mDecorator->Relayout( size );
1254 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1257 RenderText( updateTextType );
1260 // The text-field emits signals when the input style changes. These changes of style are
1261 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1262 // can't be emitted during the size negotiation as the callbacks may update the UI.
1263 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1264 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1266 if( Adaptor::IsAvailable() )
1268 Adaptor& adaptor = Adaptor::Get();
1270 if( NULL == mIdleCallback )
1272 // @note: The callback manager takes the ownership of the callback object.
1273 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1274 adaptor.AddIdle( mIdleCallback );
1280 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1282 Actor renderableActor;
1284 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1288 renderableActor = mRenderer->Render( mController->GetView(),
1290 DepthIndex::CONTENT );
1293 if( renderableActor != mRenderableActor )
1295 UnparentAndReset( mRenderableActor );
1296 mRenderableActor = renderableActor;
1300 if( mRenderableActor )
1302 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1304 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1306 // Make sure the actors are parented correctly with/without clipping
1307 Actor self = mStencil ? mStencil : Self();
1309 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1310 endIt = mClippingDecorationActors.end();
1316 mClippingDecorationActors.clear();
1318 self.Add( mRenderableActor );
1322 void TextField::OnKeyInputFocusGained()
1324 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1326 mImfManager.ApplyOptions( mInputMethodOptions );
1328 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1330 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1332 // Notify that the text editing start.
1333 mImfManager.Activate();
1335 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1336 mImfManager.SetRestoreAfterFocusLost( true );
1338 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1342 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1345 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1347 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1350 void TextField::OnKeyInputFocusLost()
1352 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1354 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1355 // The text editing is finished. Therefore the imf manager don't have restore activation.
1356 mImfManager.SetRestoreAfterFocusLost( false );
1358 // Notify that the text editing finish.
1359 mImfManager.Deactivate();
1361 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1363 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1367 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1370 mController->KeyboardFocusLostEvent();
1372 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1375 void TextField::OnTap( const TapGesture& gesture )
1377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1379 mImfManager.Activate();
1381 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1382 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1387 void TextField::OnPan( const PanGesture& gesture )
1389 mController->PanEvent( gesture.state, gesture.displacement );
1392 void TextField::OnLongPress( const LongPressGesture& gesture )
1394 mImfManager.Activate();
1396 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1401 bool TextField::OnKeyEvent( const KeyEvent& event )
1403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1405 if( Dali::DALI_KEY_ESCAPE == event.keyCode || "Return" == event.keyPressedName ) // Make a Dali key code for this
1407 // Make sure ClearKeyInputFocus when only key is up
1408 if( event.state == KeyEvent::Up )
1410 ClearKeyInputFocus();
1416 return mController->KeyEvent( event );
1419 void TextField::RequestTextRelayout()
1424 void TextField::TextChanged()
1426 Dali::Toolkit::TextField handle( GetOwner() );
1427 mTextChangedSignal.Emit( handle );
1430 void TextField::MaxLengthReached()
1432 Dali::Toolkit::TextField handle( GetOwner() );
1433 mMaxLengthReachedSignal.Emit( handle );
1436 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1438 Dali::Toolkit::TextField handle( GetOwner() );
1440 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1442 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1444 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1446 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1448 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1450 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1452 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1454 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1456 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1458 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1460 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1462 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1464 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1466 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1468 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1470 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1472 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1474 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1476 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1478 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1480 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1483 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1486 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1492 mClippingDecorationActors.push_back( actor );
1496 Self().Add( actor );
1501 void TextField::OnStageConnect( Dali::Actor actor )
1503 if ( mHasBeenStaged )
1505 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1509 mHasBeenStaged = true;
1513 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1515 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1516 return mController->OnImfEvent( imfManager, imfEvent );
1519 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1523 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1528 Scripting::CreatePropertyMap( image, map );
1534 void TextField::EnableClipping()
1538 // Creates an extra control to be used as stencil buffer.
1539 mStencil = Control::New();
1540 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1541 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1543 // Creates a background visual. Even if the color is transparent it updates the stencil.
1544 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1545 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1546 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1548 // Enable the clipping property.
1549 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1550 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1552 Self().Add( mStencil );
1556 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1558 mController->PasteClipboardItemEvent();
1561 void TextField::KeyboardStatusChanged(bool keyboardShown)
1563 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1565 // Just hide the grab handle when keyboard is hidden.
1566 if (!keyboardShown )
1568 mController->KeyboardFocusLostEvent();
1572 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1576 void TextField::OnStageConnection( int depth )
1578 // Sets the depth to the visuals inside the text's decorator.
1579 mDecorator->SetTextDepth( depth );
1581 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1583 // Call the Control::OnStageConnection() to set the depth of the background.
1584 Control::OnStageConnection( depth );
1587 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1592 void TextField::OnIdleSignal()
1594 // Emits the change of input style signals.
1595 mController->ProcessInputStyleChangedSignals();
1597 // Set the pointer to null as the callback manager deletes the callback after execute it.
1598 mIdleCallback = NULL;
1601 TextField::TextField()
1602 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1603 mIdleCallback( NULL ),
1604 mAlignmentOffset( 0.f ),
1605 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1606 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1607 mHasBeenStaged( false )
1611 TextField::~TextField()
1613 UnparentAndReset( mStencil );
1615 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1617 Adaptor::Get().RemoveIdle( mIdleCallback );
1621 } // namespace Internal
1623 } // namespace Toolkit