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 )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
147 DALI_TYPE_REGISTRATION_END()
151 Toolkit::TextField TextField::New()
153 // Create the implementation, temporarily owned by this handle on stack
154 IntrusivePtr< TextField > impl = new TextField();
156 // Pass ownership to CustomActor handle
157 Toolkit::TextField handle( *impl );
159 // Second-phase init of the implementation
160 // This can only be done after the CustomActor connection has been made...
166 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
168 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
170 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
175 TextField& impl( GetImpl( textField ) );
179 case Toolkit::TextField::Property::RENDERING_BACKEND:
181 int backend = value.Get< int >();
182 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
184 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
185 if( Text::RENDERING_VECTOR_BASED == backend )
187 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
190 if( impl.mRenderingBackend != backend )
192 impl.mRenderingBackend = backend;
193 impl.mRenderer.Reset();
195 if( impl.mController )
197 // When using the vector-based rendering, the size of the GLyphs are different
198 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
199 impl.mController->SetGlyphType( glyphType );
204 case Toolkit::TextField::Property::TEXT:
206 if( impl.mController )
208 const std::string& text = value.Get< std::string >();
209 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
211 impl.mController->SetText( text );
215 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
217 if( impl.mController )
219 const std::string& text = value.Get< std::string >();
220 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
222 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
226 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
228 if( impl.mController )
230 const std::string& text = value.Get< std::string >();
231 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
233 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
237 case Toolkit::TextField::Property::FONT_FAMILY:
239 if( impl.mController )
241 const std::string& fontFamily = value.Get< std::string >();
242 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
243 impl.mController->SetDefaultFontFamily( fontFamily );
247 case Toolkit::TextField::Property::FONT_STYLE:
249 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
252 case Toolkit::TextField::Property::POINT_SIZE:
254 if( impl.mController )
256 const float pointSize = value.Get< float >();
257 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
259 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
261 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
266 case Toolkit::TextField::Property::MAX_LENGTH:
268 if( impl.mController )
270 const int max = value.Get< int >();
271 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
273 impl.mController->SetMaximumNumberOfCharacters( max );
277 case Toolkit::TextField::Property::EXCEED_POLICY:
279 impl.mExceedPolicy = value.Get<int>();
281 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
283 impl.EnableClipping();
287 UnparentAndReset( impl.mStencil );
289 impl.RequestTextRelayout();
292 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
294 if( impl.mController )
296 const std::string& alignStr = value.Get< std::string >();
297 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
299 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
300 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
301 HORIZONTAL_ALIGNMENT_STRING_TABLE,
302 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
305 impl.mController->SetHorizontalAlignment( alignment );
310 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
312 if( impl.mController )
314 const std::string& alignStr = value.Get< std::string >();
315 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
317 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
318 if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
319 VERTICAL_ALIGNMENT_STRING_TABLE,
320 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
323 impl.mController->SetVerticalAlignment( alignment );
328 case Toolkit::TextField::Property::TEXT_COLOR:
330 if( impl.mController )
332 const Vector4& textColor = value.Get< Vector4 >();
333 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 );
335 if( impl.mController->GetDefaultColor() != textColor )
337 impl.mController->SetDefaultColor( textColor );
338 impl.mController->SetInputColor( textColor );
339 impl.mRenderer.Reset();
344 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
346 if( impl.mController )
348 const Vector4& textColor = value.Get< Vector4 >();
349 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 );
351 if( impl.mController->GetPlaceholderTextColor() != textColor )
353 impl.mController->SetPlaceholderTextColor( textColor );
354 impl.mRenderer.Reset();
359 case Toolkit::TextField::Property::SHADOW_OFFSET:
361 if( impl.mController )
363 const Vector2& shadowOffset = value.Get< Vector2 >();
364 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
366 if ( impl.mController->GetShadowOffset() != shadowOffset )
368 impl.mController->SetShadowOffset( shadowOffset );
369 impl.mRenderer.Reset();
374 case Toolkit::TextField::Property::SHADOW_COLOR:
376 if( impl.mController )
378 const Vector4& shadowColor = value.Get< Vector4 >();
379 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 );
381 if ( impl.mController->GetShadowColor() != shadowColor )
383 impl.mController->SetShadowColor( shadowColor );
384 impl.mRenderer.Reset();
389 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
391 if( impl.mDecorator )
393 const Vector4& color = value.Get< Vector4 >();
394 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 );
396 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
397 impl.RequestTextRelayout();
401 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
403 if( impl.mDecorator )
405 const Vector4& color = value.Get< Vector4 >();
406 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 );
408 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
409 impl.RequestTextRelayout();
413 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
415 if( impl.mController )
417 const bool enable = value.Get< bool >();
418 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
420 impl.mController->SetEnableCursorBlink( enable );
421 impl.RequestTextRelayout();
425 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
427 if( impl.mDecorator )
429 const float interval = value.Get< float >();
430 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
432 impl.mDecorator->SetCursorBlinkInterval( interval );
436 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
438 if( impl.mDecorator )
440 const float duration = value.Get< float >();
441 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
443 impl.mDecorator->SetCursorBlinkDuration( duration );
447 case Toolkit::TextField::Property::CURSOR_WIDTH:
449 if( impl.mDecorator )
451 const int width = value.Get< int >();
452 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
454 impl.mDecorator->SetCursorWidth( width );
455 impl.mController->GetLayoutEngine().SetCursorWidth( width );
459 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
461 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
462 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
464 if( impl.mDecorator )
466 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
467 impl.RequestTextRelayout();
471 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
473 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
474 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
476 if( impl.mDecorator )
478 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
479 impl.RequestTextRelayout();
483 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
485 const float threshold = value.Get< float >();
486 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
488 if( impl.mDecorator )
490 impl.mDecorator->SetScrollThreshold( threshold );
494 case Toolkit::TextField::Property::SCROLL_SPEED:
496 const float speed = value.Get< float >();
497 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
499 if( impl.mDecorator )
501 impl.mDecorator->SetScrollSpeed( speed );
505 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
507 const Image image = Scripting::NewImage( value );
509 if( impl.mDecorator && image )
511 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
512 impl.RequestTextRelayout();
516 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
518 const Image image = Scripting::NewImage( value );
520 if( impl.mDecorator && image )
522 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
523 impl.RequestTextRelayout();
527 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
529 const Image image = Scripting::NewImage( value );
531 if( impl.mDecorator && image )
533 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
534 impl.RequestTextRelayout();
538 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
540 const Image image = Scripting::NewImage( value );
542 if( impl.mDecorator && image )
544 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
545 impl.RequestTextRelayout();
549 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
551 const Image image = Scripting::NewImage( value );
553 if( impl.mDecorator && image )
555 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
556 impl.RequestTextRelayout();
560 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
562 const Image image = Scripting::NewImage( value );
564 if( impl.mDecorator && image )
566 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
567 impl.RequestTextRelayout();
571 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
573 const Vector4 color = value.Get< Vector4 >();
574 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 );
576 if( impl.mDecorator )
578 impl.mDecorator->SetHighlightColor( color );
579 impl.RequestTextRelayout();
583 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
585 if( impl.mDecorator )
587 const Rect<int> box = value.Get< Rect<int> >();
588 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 );
590 impl.mDecorator->SetBoundingBox( box );
591 impl.RequestTextRelayout();
595 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
597 const Property::Map* map = value.GetMap();
600 impl.mInputMethodOptions.ApplyProperty( *map );
602 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
604 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
605 if (control == textField)
607 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
611 case Toolkit::TextField::Property::INPUT_COLOR:
613 if( impl.mController )
615 const Vector4 inputColor = value.Get< Vector4 >();
616 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 );
618 impl.mController->SetInputColor( inputColor );
622 case Toolkit::TextField::Property::ENABLE_MARKUP:
624 if( impl.mController )
626 const bool enableMarkup = value.Get<bool>();
627 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
629 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
633 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
635 if( impl.mController )
637 const std::string& fontFamily = value.Get< std::string >();
638 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
639 impl.mController->SetInputFontFamily( fontFamily );
643 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
645 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
648 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
650 if( impl.mController )
652 const float pointSize = value.Get< float >();
653 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
654 impl.mController->SetInputFontPointSize( pointSize );
658 case Toolkit::TextField::Property::UNDERLINE:
660 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
663 impl.mRenderer.Reset();
667 case Toolkit::TextField::Property::INPUT_UNDERLINE:
669 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
672 impl.mRenderer.Reset();
676 case Toolkit::TextField::Property::SHADOW:
678 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
681 impl.mRenderer.Reset();
685 case Toolkit::TextField::Property::INPUT_SHADOW:
687 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
690 impl.mRenderer.Reset();
694 case Toolkit::TextField::Property::EMBOSS:
696 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
699 impl.mRenderer.Reset();
703 case Toolkit::TextField::Property::INPUT_EMBOSS:
705 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
708 impl.mRenderer.Reset();
712 case Toolkit::TextField::Property::OUTLINE:
714 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
717 impl.mRenderer.Reset();
721 case Toolkit::TextField::Property::INPUT_OUTLINE:
723 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
726 impl.mRenderer.Reset();
730 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
732 const Property::Map* map = value.GetMap();
735 impl.mController->SetHiddenInputOption(*map);
739 case Toolkit::DevelTextField::Property::PIXEL_SIZE:
741 if( impl.mController )
743 const float pixelSize = value.Get< float >();
744 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
746 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
748 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
757 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
759 Property::Value value;
761 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
765 TextField& impl( GetImpl( textField ) );
769 case Toolkit::TextField::Property::RENDERING_BACKEND:
771 value = impl.mRenderingBackend;
774 case Toolkit::TextField::Property::TEXT:
776 if( impl.mController )
779 impl.mController->GetText( text );
780 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
785 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
787 if( impl.mController )
790 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
795 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
797 if( impl.mController )
800 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
805 case Toolkit::TextField::Property::FONT_FAMILY:
807 if( impl.mController )
809 value = impl.mController->GetDefaultFontFamily();
813 case Toolkit::TextField::Property::FONT_STYLE:
815 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
818 case Toolkit::TextField::Property::POINT_SIZE:
820 if( impl.mController )
822 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
826 case Toolkit::TextField::Property::MAX_LENGTH:
828 if( impl.mController )
830 value = impl.mController->GetMaximumNumberOfCharacters();
834 case Toolkit::TextField::Property::EXCEED_POLICY:
836 value = impl.mExceedPolicy;
839 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
841 if( impl.mController )
843 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
844 HORIZONTAL_ALIGNMENT_STRING_TABLE,
845 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
848 value = std::string( name );
853 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
855 if( impl.mController )
857 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
858 VERTICAL_ALIGNMENT_STRING_TABLE,
859 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
862 value = std::string( name );
867 case Toolkit::TextField::Property::TEXT_COLOR:
869 if ( impl.mController )
871 value = impl.mController->GetDefaultColor();
875 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
877 if ( impl.mController )
879 value = impl.mController->GetPlaceholderTextColor();
883 case Toolkit::TextField::Property::SHADOW_OFFSET:
885 if ( impl.mController )
887 value = impl.mController->GetShadowOffset();
891 case Toolkit::TextField::Property::SHADOW_COLOR:
893 if ( impl.mController )
895 value = impl.mController->GetShadowColor();
899 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
901 if( impl.mDecorator )
903 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
907 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
909 if( impl.mDecorator )
911 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
915 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
917 value = impl.mController->GetEnableCursorBlink();
920 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
922 if( impl.mDecorator )
924 value = impl.mDecorator->GetCursorBlinkInterval();
928 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
930 if( impl.mDecorator )
932 value = impl.mDecorator->GetCursorBlinkDuration();
936 case Toolkit::TextField::Property::CURSOR_WIDTH:
938 if( impl.mDecorator )
940 value = impl.mDecorator->GetCursorWidth();
944 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
946 if( impl.mDecorator )
948 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
951 value = image.GetUrl();
956 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
958 if( impl.mDecorator )
960 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
963 value = image.GetUrl();
968 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
970 if( impl.mDecorator )
972 value = impl.mDecorator->GetScrollThreshold();
976 case Toolkit::TextField::Property::SCROLL_SPEED:
978 if( impl.mDecorator )
980 value = impl.mDecorator->GetScrollSpeed();
984 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
986 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
989 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
991 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
994 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
996 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
999 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1001 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1004 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1006 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1009 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1011 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1014 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1016 if( impl.mDecorator )
1018 value = impl.mDecorator->GetHighlightColor();
1022 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1024 if( impl.mDecorator )
1026 Rect<int> boundingBox;
1027 impl.mDecorator->GetBoundingBox( boundingBox );
1028 value = boundingBox;
1032 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1035 impl.mInputMethodOptions.RetrieveProperty( map );
1039 case Toolkit::TextField::Property::INPUT_COLOR:
1041 if( impl.mController )
1043 value = impl.mController->GetInputColor();
1047 case Toolkit::TextField::Property::ENABLE_MARKUP:
1049 if( impl.mController )
1051 value = impl.mController->IsMarkupProcessorEnabled();
1055 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1057 if( impl.mController )
1059 value = impl.mController->GetInputFontFamily();
1063 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1065 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1068 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1070 if( impl.mController )
1072 value = impl.mController->GetInputFontPointSize();
1076 case Toolkit::TextField::Property::UNDERLINE:
1078 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1081 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1083 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1086 case Toolkit::TextField::Property::SHADOW:
1088 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1091 case Toolkit::TextField::Property::INPUT_SHADOW:
1093 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1096 case Toolkit::TextField::Property::EMBOSS:
1098 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1101 case Toolkit::TextField::Property::INPUT_EMBOSS:
1103 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1106 case Toolkit::TextField::Property::OUTLINE:
1108 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1111 case Toolkit::TextField::Property::INPUT_OUTLINE:
1113 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1116 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
1119 impl.mController->GetHiddenInputOption(map);
1123 case Toolkit::DevelTextField::Property::PIXEL_SIZE:
1125 if( impl.mController )
1127 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1137 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1139 Dali::BaseHandle handle( object );
1141 bool connected( true );
1142 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1144 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1146 field.TextChangedSignal().Connect( tracker, functor );
1148 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1150 field.MaxLengthReachedSignal().Connect( tracker, functor );
1152 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1154 field.InputStyleChangedSignal().Connect( tracker, functor );
1158 // signalName does not match any signal
1165 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1167 return mTextChangedSignal;
1170 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1172 return mMaxLengthReachedSignal;
1175 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1177 return mInputStyleChangedSignal;
1180 void TextField::OnInitialize()
1182 Actor self = Self();
1184 mController = Text::Controller::New( this, this );
1186 // When using the vector-based rendering, the size of the GLyphs are different
1187 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1188 mController->SetGlyphType( glyphType );
1190 mDecorator = Text::Decorator::New( *mController,
1193 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1195 // Enables the text input.
1196 mController->EnableTextInput( mDecorator );
1198 // Enables the horizontal scrolling after the text input has been enabled.
1199 mController->SetHorizontalScrollEnabled( true );
1201 // Disables the vertical scrolling.
1202 mController->SetVerticalScrollEnabled( false );
1204 // Disable the smooth handle panning.
1205 mController->SetSmoothHandlePanEnabled( false );
1207 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1208 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1210 // Forward input events to controller
1211 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1212 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1214 mImfManager = ImfManager::Get();
1216 self.TouchSignal().Connect( this, &TextField::OnTouched );
1218 // Set BoundingBox to stage size if not already set.
1219 Rect<int> boundingBox;
1220 mDecorator->GetBoundingBox( boundingBox );
1222 if( boundingBox.IsEmpty() )
1224 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1225 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1228 // Flip vertically the 'left' selection handle
1229 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1231 // Fill-parent area by default
1232 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1233 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1234 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1236 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1242 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1244 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1248 case StyleChange::DEFAULT_FONT_CHANGE:
1250 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1251 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1252 // Property system did not set the font so should update it.
1253 mController->UpdateAfterFontChange( newFont );
1258 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1260 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1264 case StyleChange::THEME_CHANGE:
1266 // Nothing to do, let control base class handle this
1271 // Up call to Control
1272 Control::OnStyleChange( styleManager, change );
1275 Vector3 TextField::GetNaturalSize()
1277 return mController->GetNaturalSize();
1280 float TextField::GetHeightForWidth( float width )
1282 return mController->GetHeightForWidth( width );
1285 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1287 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1289 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1291 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1294 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1297 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1299 mDecorator->Relayout( size );
1304 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1307 RenderText( updateTextType );
1310 // The text-field emits signals when the input style changes. These changes of style are
1311 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1312 // can't be emitted during the size negotiation as the callbacks may update the UI.
1313 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1314 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1316 if( Adaptor::IsAvailable() )
1318 Adaptor& adaptor = Adaptor::Get();
1320 if( NULL == mIdleCallback )
1322 // @note: The callback manager takes the ownership of the callback object.
1323 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1324 adaptor.AddIdle( mIdleCallback );
1330 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1332 Actor renderableActor;
1334 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1338 renderableActor = mRenderer->Render( mController->GetView(),
1340 DepthIndex::CONTENT );
1343 if( renderableActor != mRenderableActor )
1345 UnparentAndReset( mRenderableActor );
1346 mRenderableActor = renderableActor;
1350 if( mRenderableActor )
1352 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1354 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1356 // Make sure the actors are parented correctly with/without clipping
1357 Actor self = mStencil ? mStencil : Self();
1359 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1360 endIt = mClippingDecorationActors.end();
1366 mClippingDecorationActors.clear();
1368 self.Add( mRenderableActor );
1372 void TextField::OnKeyInputFocusGained()
1374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1376 mImfManager.ApplyOptions( mInputMethodOptions );
1378 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1380 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1382 // Notify that the text editing start.
1383 mImfManager.Activate();
1385 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1386 mImfManager.SetRestoreAfterFocusLost( true );
1388 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1392 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1395 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1397 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1400 void TextField::OnKeyInputFocusLost()
1402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1404 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1405 // The text editing is finished. Therefore the imf manager don't have restore activation.
1406 mImfManager.SetRestoreAfterFocusLost( false );
1408 // Notify that the text editing finish.
1409 mImfManager.Deactivate();
1411 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1413 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1417 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1420 mController->KeyboardFocusLostEvent();
1422 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1425 void TextField::OnTap( const TapGesture& gesture )
1427 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1429 mImfManager.Activate();
1431 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1432 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1437 void TextField::OnPan( const PanGesture& gesture )
1439 mController->PanEvent( gesture.state, gesture.displacement );
1442 void TextField::OnLongPress( const LongPressGesture& gesture )
1444 mImfManager.Activate();
1446 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1451 bool TextField::OnKeyEvent( const KeyEvent& event )
1453 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1455 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1457 // Make sure ClearKeyInputFocus when only key is up
1458 if( event.state == KeyEvent::Up )
1460 ClearKeyInputFocus();
1466 return mController->KeyEvent( event );
1469 void TextField::RequestTextRelayout()
1474 void TextField::TextChanged()
1476 Dali::Toolkit::TextField handle( GetOwner() );
1477 mTextChangedSignal.Emit( handle );
1480 void TextField::MaxLengthReached()
1482 Dali::Toolkit::TextField handle( GetOwner() );
1483 mMaxLengthReachedSignal.Emit( handle );
1486 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1488 Dali::Toolkit::TextField handle( GetOwner() );
1490 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1492 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1494 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1496 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1498 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1500 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1502 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1504 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1506 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1508 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1510 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1512 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1514 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1516 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1518 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1520 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1522 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1524 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1526 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1528 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1530 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1533 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1536 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1542 mClippingDecorationActors.push_back( actor );
1546 Self().Add( actor );
1551 void TextField::OnStageConnect( Dali::Actor actor )
1553 if ( mHasBeenStaged )
1555 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1559 mHasBeenStaged = true;
1563 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1565 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1566 return mController->OnImfEvent( imfManager, imfEvent );
1569 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1573 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1578 Scripting::CreatePropertyMap( image, map );
1584 void TextField::EnableClipping()
1588 // Creates an extra control to be used as stencil buffer.
1589 mStencil = Control::New();
1590 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1591 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1593 // Creates a background visual. Even if the color is transparent it updates the stencil.
1594 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1595 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1596 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1598 // Enable the clipping property.
1599 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1600 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1602 Self().Add( mStencil );
1606 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1608 mController->PasteClipboardItemEvent();
1611 void TextField::KeyboardStatusChanged(bool keyboardShown)
1613 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1615 // Just hide the grab handle when keyboard is hidden.
1616 if (!keyboardShown )
1618 mController->KeyboardFocusLostEvent();
1622 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1626 void TextField::OnStageConnection( int depth )
1628 // Sets the depth to the visuals inside the text's decorator.
1629 mDecorator->SetTextDepth( depth );
1631 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1633 // Call the Control::OnStageConnection() to set the depth of the background.
1634 Control::OnStageConnection( depth );
1637 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1642 void TextField::OnIdleSignal()
1644 // Emits the change of input style signals.
1645 mController->ProcessInputStyleChangedSignals();
1647 // Set the pointer to null as the callback manager deletes the callback after execute it.
1648 mIdleCallback = NULL;
1651 TextField::TextField()
1652 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1653 mIdleCallback( NULL ),
1654 mAlignmentOffset( 0.f ),
1655 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1656 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1657 mHasBeenStaged( false )
1661 TextField::~TextField()
1663 UnparentAndReset( mStencil );
1665 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1667 Adaptor::Get().RemoveIdle( mIdleCallback );
1671 } // namespace Internal
1673 } // namespace Toolkit