2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/devel-api/object/property-helper-devel.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptors/adaptor.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
38 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
39 #include <dali-toolkit/internal/text/rendering/text-backend.h>
40 #include <dali-toolkit/internal/text/text-effects-style.h>
41 #include <dali-toolkit/internal/text/text-font-style.h>
42 #include <dali-toolkit/internal/text/text-view.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
45 using namespace Dali::Toolkit::Text;
56 namespace // unnamed namespace
59 #if defined(DEBUG_ENABLED)
60 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
63 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
64 } // unnamed namespace
69 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
71 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
72 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
73 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
75 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
77 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
79 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
80 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
81 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
83 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
88 return Toolkit::TextField::New();
91 // Setup properties, signals and actions using the type-registry.
92 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
138 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
139 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
140 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
143 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
146 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
147 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
149 DALI_TYPE_REGISTRATION_END()
153 Toolkit::TextField TextField::New()
155 // Create the implementation, temporarily owned by this handle on stack
156 IntrusivePtr< TextField > impl = new TextField();
158 // Pass ownership to CustomActor handle
159 Toolkit::TextField handle( *impl );
161 // Second-phase init of the implementation
162 // This can only be done after the CustomActor connection has been made...
168 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
170 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
172 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
177 TextField& impl( GetImpl( textField ) );
181 case Toolkit::TextField::Property::RENDERING_BACKEND:
183 int backend = value.Get< int >();
184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
186 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
187 if( Text::RENDERING_VECTOR_BASED == backend )
189 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
192 if( impl.mRenderingBackend != backend )
194 impl.mRenderingBackend = backend;
195 impl.mRenderer.Reset();
197 if( impl.mController )
199 // When using the vector-based rendering, the size of the GLyphs are different
200 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
201 impl.mController->SetGlyphType( glyphType );
206 case Toolkit::TextField::Property::TEXT:
208 if( impl.mController )
210 const std::string& text = value.Get< std::string >();
211 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
213 impl.mController->SetText( text );
217 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
219 if( impl.mController )
221 const std::string& text = value.Get< std::string >();
222 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
224 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
228 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
230 if( impl.mController )
232 const std::string& text = value.Get< std::string >();
233 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
235 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
239 case Toolkit::TextField::Property::FONT_FAMILY:
241 if( impl.mController )
243 const std::string& fontFamily = value.Get< std::string >();
244 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
245 impl.mController->SetDefaultFontFamily( fontFamily );
249 case Toolkit::TextField::Property::FONT_STYLE:
251 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
254 case Toolkit::TextField::Property::POINT_SIZE:
256 if( impl.mController )
258 const float pointSize = value.Get< float >();
259 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
261 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
263 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
268 case Toolkit::TextField::Property::MAX_LENGTH:
270 if( impl.mController )
272 const int max = value.Get< int >();
273 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
275 impl.mController->SetMaximumNumberOfCharacters( max );
279 case Toolkit::TextField::Property::EXCEED_POLICY:
281 impl.mExceedPolicy = value.Get<int>();
283 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
285 impl.EnableClipping();
289 UnparentAndReset( impl.mStencil );
291 impl.RequestTextRelayout();
294 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
296 if( impl.mController )
298 const std::string& alignStr = value.Get< std::string >();
299 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
301 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
302 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
303 HORIZONTAL_ALIGNMENT_STRING_TABLE,
304 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
307 impl.mController->SetHorizontalAlignment( alignment );
312 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
314 if( impl.mController )
316 const std::string& alignStr = value.Get< std::string >();
317 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
319 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
320 if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
321 VERTICAL_ALIGNMENT_STRING_TABLE,
322 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
325 impl.mController->SetVerticalAlignment( alignment );
330 case Toolkit::TextField::Property::TEXT_COLOR:
332 if( impl.mController )
334 const Vector4& textColor = value.Get< Vector4 >();
335 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 );
337 if( impl.mController->GetDefaultColor() != textColor )
339 impl.mController->SetDefaultColor( textColor );
340 impl.mController->SetInputColor( textColor );
341 impl.mRenderer.Reset();
346 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
348 if( impl.mController )
350 const Vector4& textColor = value.Get< Vector4 >();
351 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 );
353 if( impl.mController->GetPlaceholderTextColor() != textColor )
355 impl.mController->SetPlaceholderTextColor( textColor );
356 impl.mRenderer.Reset();
361 case Toolkit::TextField::Property::SHADOW_OFFSET:
363 if( impl.mController )
365 const Vector2& shadowOffset = value.Get< Vector2 >();
366 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
368 if ( impl.mController->GetShadowOffset() != shadowOffset )
370 impl.mController->SetShadowOffset( shadowOffset );
371 impl.mRenderer.Reset();
376 case Toolkit::TextField::Property::SHADOW_COLOR:
378 if( impl.mController )
380 const Vector4& shadowColor = value.Get< Vector4 >();
381 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 );
383 if ( impl.mController->GetShadowColor() != shadowColor )
385 impl.mController->SetShadowColor( shadowColor );
386 impl.mRenderer.Reset();
391 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
393 if( impl.mDecorator )
395 const Vector4& color = value.Get< Vector4 >();
396 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 );
398 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
399 impl.RequestTextRelayout();
403 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
405 if( impl.mDecorator )
407 const Vector4& color = value.Get< Vector4 >();
408 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 );
410 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
411 impl.RequestTextRelayout();
415 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
417 if( impl.mController )
419 const bool enable = value.Get< bool >();
420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
422 impl.mController->SetEnableCursorBlink( enable );
423 impl.RequestTextRelayout();
427 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
429 if( impl.mDecorator )
431 const float interval = value.Get< float >();
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
434 impl.mDecorator->SetCursorBlinkInterval( interval );
438 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
440 if( impl.mDecorator )
442 const float duration = value.Get< float >();
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
445 impl.mDecorator->SetCursorBlinkDuration( duration );
449 case Toolkit::TextField::Property::CURSOR_WIDTH:
451 if( impl.mDecorator )
453 const int width = value.Get< int >();
454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
456 impl.mDecorator->SetCursorWidth( width );
457 impl.mController->GetLayoutEngine().SetCursorWidth( width );
461 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
463 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
464 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
466 if( impl.mDecorator )
468 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
469 impl.RequestTextRelayout();
473 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
475 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
476 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
478 if( impl.mDecorator )
480 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
487 const float threshold = value.Get< float >();
488 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
490 if( impl.mDecorator )
492 impl.mDecorator->SetScrollThreshold( threshold );
496 case Toolkit::TextField::Property::SCROLL_SPEED:
498 const float speed = value.Get< float >();
499 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
501 if( impl.mDecorator )
503 impl.mDecorator->SetScrollSpeed( speed );
507 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator && image )
513 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
520 const Image image = Scripting::NewImage( value );
522 if( impl.mDecorator && image )
524 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
525 impl.RequestTextRelayout();
529 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
531 const Image image = Scripting::NewImage( value );
533 if( impl.mDecorator && image )
535 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
536 impl.RequestTextRelayout();
540 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
542 const Image image = Scripting::NewImage( value );
544 if( impl.mDecorator && image )
546 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
547 impl.RequestTextRelayout();
551 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
553 const Image image = Scripting::NewImage( value );
555 if( impl.mDecorator && image )
557 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
558 impl.RequestTextRelayout();
562 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
564 const Image image = Scripting::NewImage( value );
566 if( impl.mDecorator && image )
568 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
569 impl.RequestTextRelayout();
573 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
575 const Vector4 color = value.Get< Vector4 >();
576 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 );
578 if( impl.mDecorator )
580 impl.mDecorator->SetHighlightColor( color );
581 impl.RequestTextRelayout();
585 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
587 if( impl.mDecorator )
589 const Rect<int> box = value.Get< Rect<int> >();
590 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 );
592 impl.mDecorator->SetBoundingBox( box );
593 impl.RequestTextRelayout();
597 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
599 const Property::Map* map = value.GetMap();
602 impl.mInputMethodOptions.ApplyProperty( *map );
604 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
606 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
607 if (control == textField)
609 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
613 case Toolkit::TextField::Property::INPUT_COLOR:
615 if( impl.mController )
617 const Vector4 inputColor = value.Get< Vector4 >();
618 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 );
620 impl.mController->SetInputColor( inputColor );
624 case Toolkit::TextField::Property::ENABLE_MARKUP:
626 if( impl.mController )
628 const bool enableMarkup = value.Get<bool>();
629 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
631 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
635 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
637 if( impl.mController )
639 const std::string& fontFamily = value.Get< std::string >();
640 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
641 impl.mController->SetInputFontFamily( fontFamily );
645 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
647 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
650 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
652 if( impl.mController )
654 const float pointSize = value.Get< float >();
655 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
656 impl.mController->SetInputFontPointSize( pointSize );
660 case Toolkit::TextField::Property::UNDERLINE:
662 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
665 impl.mRenderer.Reset();
669 case Toolkit::TextField::Property::INPUT_UNDERLINE:
671 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
674 impl.mRenderer.Reset();
678 case Toolkit::TextField::Property::SHADOW:
680 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
683 impl.mRenderer.Reset();
687 case Toolkit::TextField::Property::INPUT_SHADOW:
689 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
692 impl.mRenderer.Reset();
696 case Toolkit::TextField::Property::EMBOSS:
698 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
701 impl.mRenderer.Reset();
705 case Toolkit::TextField::Property::INPUT_EMBOSS:
707 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
710 impl.mRenderer.Reset();
714 case Toolkit::TextField::Property::OUTLINE:
716 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
719 impl.mRenderer.Reset();
723 case Toolkit::TextField::Property::INPUT_OUTLINE:
725 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
728 impl.mRenderer.Reset();
732 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
734 const Property::Map* map = value.GetMap();
737 impl.mController->SetHiddenInputOption(*map);
741 case Toolkit::DevelTextField::Property::PIXEL_SIZE:
743 if( impl.mController )
745 const float pixelSize = value.Get< float >();
746 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
748 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
750 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
755 case Toolkit::DevelTextField::Property::ENABLE_SELECTION:
757 if( impl.mController )
759 const bool enableSelection = value.Get< bool >();
760 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
761 impl.mController->SetSelectionEnabled( enableSelection );
769 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
771 Property::Value value;
773 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
777 TextField& impl( GetImpl( textField ) );
781 case Toolkit::TextField::Property::RENDERING_BACKEND:
783 value = impl.mRenderingBackend;
786 case Toolkit::TextField::Property::TEXT:
788 if( impl.mController )
791 impl.mController->GetText( text );
792 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
797 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
799 if( impl.mController )
802 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
807 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
809 if( impl.mController )
812 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
817 case Toolkit::TextField::Property::FONT_FAMILY:
819 if( impl.mController )
821 value = impl.mController->GetDefaultFontFamily();
825 case Toolkit::TextField::Property::FONT_STYLE:
827 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
830 case Toolkit::TextField::Property::POINT_SIZE:
832 if( impl.mController )
834 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
838 case Toolkit::TextField::Property::MAX_LENGTH:
840 if( impl.mController )
842 value = impl.mController->GetMaximumNumberOfCharacters();
846 case Toolkit::TextField::Property::EXCEED_POLICY:
848 value = impl.mExceedPolicy;
851 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
853 if( impl.mController )
855 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
856 HORIZONTAL_ALIGNMENT_STRING_TABLE,
857 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
860 value = std::string( name );
865 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
867 if( impl.mController )
869 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
870 VERTICAL_ALIGNMENT_STRING_TABLE,
871 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
874 value = std::string( name );
879 case Toolkit::TextField::Property::TEXT_COLOR:
881 if ( impl.mController )
883 value = impl.mController->GetDefaultColor();
887 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
889 if ( impl.mController )
891 value = impl.mController->GetPlaceholderTextColor();
895 case Toolkit::TextField::Property::SHADOW_OFFSET:
897 if ( impl.mController )
899 value = impl.mController->GetShadowOffset();
903 case Toolkit::TextField::Property::SHADOW_COLOR:
905 if ( impl.mController )
907 value = impl.mController->GetShadowColor();
911 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
913 if( impl.mDecorator )
915 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
919 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
921 if( impl.mDecorator )
923 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
927 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
929 value = impl.mController->GetEnableCursorBlink();
932 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
934 if( impl.mDecorator )
936 value = impl.mDecorator->GetCursorBlinkInterval();
940 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
942 if( impl.mDecorator )
944 value = impl.mDecorator->GetCursorBlinkDuration();
948 case Toolkit::TextField::Property::CURSOR_WIDTH:
950 if( impl.mDecorator )
952 value = impl.mDecorator->GetCursorWidth();
956 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
958 if( impl.mDecorator )
960 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
963 value = image.GetUrl();
968 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
970 if( impl.mDecorator )
972 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
975 value = image.GetUrl();
980 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
982 if( impl.mDecorator )
984 value = impl.mDecorator->GetScrollThreshold();
988 case Toolkit::TextField::Property::SCROLL_SPEED:
990 if( impl.mDecorator )
992 value = impl.mDecorator->GetScrollSpeed();
996 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
998 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1001 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1003 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1006 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1008 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1011 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1013 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1016 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1018 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1021 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1023 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1026 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1028 if( impl.mDecorator )
1030 value = impl.mDecorator->GetHighlightColor();
1034 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1036 if( impl.mDecorator )
1038 Rect<int> boundingBox;
1039 impl.mDecorator->GetBoundingBox( boundingBox );
1040 value = boundingBox;
1044 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1047 impl.mInputMethodOptions.RetrieveProperty( map );
1051 case Toolkit::TextField::Property::INPUT_COLOR:
1053 if( impl.mController )
1055 value = impl.mController->GetInputColor();
1059 case Toolkit::TextField::Property::ENABLE_MARKUP:
1061 if( impl.mController )
1063 value = impl.mController->IsMarkupProcessorEnabled();
1067 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1069 if( impl.mController )
1071 value = impl.mController->GetInputFontFamily();
1075 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1077 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1080 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1082 if( impl.mController )
1084 value = impl.mController->GetInputFontPointSize();
1088 case Toolkit::TextField::Property::UNDERLINE:
1090 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1093 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1095 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1098 case Toolkit::TextField::Property::SHADOW:
1100 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1103 case Toolkit::TextField::Property::INPUT_SHADOW:
1105 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1108 case Toolkit::TextField::Property::EMBOSS:
1110 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1113 case Toolkit::TextField::Property::INPUT_EMBOSS:
1115 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1118 case Toolkit::TextField::Property::OUTLINE:
1120 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1123 case Toolkit::TextField::Property::INPUT_OUTLINE:
1125 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1128 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
1131 impl.mController->GetHiddenInputOption(map);
1135 case Toolkit::DevelTextField::Property::PIXEL_SIZE:
1137 if( impl.mController )
1139 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1143 case Toolkit::DevelTextField::Property::ENABLE_SELECTION:
1145 if( impl.mController )
1147 value = impl.mController->IsSelectionEnabled();
1157 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1159 Dali::BaseHandle handle( object );
1161 bool connected( true );
1162 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1164 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1166 field.TextChangedSignal().Connect( tracker, functor );
1168 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1170 field.MaxLengthReachedSignal().Connect( tracker, functor );
1172 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1174 field.InputStyleChangedSignal().Connect( tracker, functor );
1178 // signalName does not match any signal
1185 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1187 return mTextChangedSignal;
1190 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1192 return mMaxLengthReachedSignal;
1195 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1197 return mInputStyleChangedSignal;
1200 void TextField::OnInitialize()
1202 Actor self = Self();
1204 mController = Text::Controller::New( this, this );
1206 // When using the vector-based rendering, the size of the GLyphs are different
1207 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1208 mController->SetGlyphType( glyphType );
1210 mDecorator = Text::Decorator::New( *mController,
1213 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1215 // Enables the text input.
1216 mController->EnableTextInput( mDecorator );
1218 // Enables the horizontal scrolling after the text input has been enabled.
1219 mController->SetHorizontalScrollEnabled( true );
1221 // Disables the vertical scrolling.
1222 mController->SetVerticalScrollEnabled( false );
1224 // Disable the smooth handle panning.
1225 mController->SetSmoothHandlePanEnabled( false );
1227 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1228 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1230 // Forward input events to controller
1231 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1232 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1234 mImfManager = ImfManager::Get();
1236 self.TouchSignal().Connect( this, &TextField::OnTouched );
1238 // Set BoundingBox to stage size if not already set.
1239 Rect<int> boundingBox;
1240 mDecorator->GetBoundingBox( boundingBox );
1242 if( boundingBox.IsEmpty() )
1244 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1245 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1248 // Flip vertically the 'left' selection handle
1249 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1251 // Fill-parent area by default
1252 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1253 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1254 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1256 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1262 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1264 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1268 case StyleChange::DEFAULT_FONT_CHANGE:
1270 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1271 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1272 // Property system did not set the font so should update it.
1273 mController->UpdateAfterFontChange( newFont );
1278 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1280 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1284 case StyleChange::THEME_CHANGE:
1286 // Nothing to do, let control base class handle this
1291 // Up call to Control
1292 Control::OnStyleChange( styleManager, change );
1295 Vector3 TextField::GetNaturalSize()
1297 return mController->GetNaturalSize();
1300 float TextField::GetHeightForWidth( float width )
1302 return mController->GetHeightForWidth( width );
1305 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1307 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1309 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1311 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1314 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1317 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1319 mDecorator->Relayout( size );
1324 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1327 RenderText( updateTextType );
1330 // The text-field emits signals when the input style changes. These changes of style are
1331 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1332 // can't be emitted during the size negotiation as the callbacks may update the UI.
1333 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1334 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1336 if( Adaptor::IsAvailable() )
1338 Adaptor& adaptor = Adaptor::Get();
1340 if( NULL == mIdleCallback )
1342 // @note: The callback manager takes the ownership of the callback object.
1343 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1344 adaptor.AddIdle( mIdleCallback );
1350 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1352 Actor renderableActor;
1354 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1358 renderableActor = mRenderer->Render( mController->GetView(),
1360 DepthIndex::CONTENT );
1363 if( renderableActor != mRenderableActor )
1365 UnparentAndReset( mRenderableActor );
1366 mRenderableActor = renderableActor;
1370 if( mRenderableActor )
1372 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1374 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1376 // Make sure the actors are parented correctly with/without clipping
1377 Actor self = mStencil ? mStencil : Self();
1379 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1380 endIt = mClippingDecorationActors.end();
1385 DevelActor::LowerToBottom(*it);
1387 mClippingDecorationActors.clear();
1389 self.Add( mRenderableActor );
1393 void TextField::OnKeyInputFocusGained()
1395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1397 mImfManager.ApplyOptions( mInputMethodOptions );
1399 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1401 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1403 // Notify that the text editing start.
1404 mImfManager.Activate();
1406 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1407 mImfManager.SetRestoreAfterFocusLost( true );
1409 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1413 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1416 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1418 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1421 void TextField::OnKeyInputFocusLost()
1423 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1425 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1426 // The text editing is finished. Therefore the imf manager don't have restore activation.
1427 mImfManager.SetRestoreAfterFocusLost( false );
1429 // Notify that the text editing finish.
1430 mImfManager.Deactivate();
1432 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1434 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1438 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1441 mController->KeyboardFocusLostEvent();
1443 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1446 void TextField::OnTap( const TapGesture& gesture )
1448 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1450 mImfManager.Activate();
1452 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1453 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1458 void TextField::OnPan( const PanGesture& gesture )
1460 mController->PanEvent( gesture.state, gesture.displacement );
1463 void TextField::OnLongPress( const LongPressGesture& gesture )
1465 mImfManager.Activate();
1467 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1472 bool TextField::OnKeyEvent( const KeyEvent& event )
1474 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1476 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1478 // Make sure ClearKeyInputFocus when only key is up
1479 if( event.state == KeyEvent::Up )
1481 ClearKeyInputFocus();
1487 return mController->KeyEvent( event );
1490 void TextField::RequestTextRelayout()
1495 void TextField::TextChanged()
1497 Dali::Toolkit::TextField handle( GetOwner() );
1498 mTextChangedSignal.Emit( handle );
1501 void TextField::MaxLengthReached()
1503 Dali::Toolkit::TextField handle( GetOwner() );
1504 mMaxLengthReachedSignal.Emit( handle );
1507 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1509 Dali::Toolkit::TextField handle( GetOwner() );
1511 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1513 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1515 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1517 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1519 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1521 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1523 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1525 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1527 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1529 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1531 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1533 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1535 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1537 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1539 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1541 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1543 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1545 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1547 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1549 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1551 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1554 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1557 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1563 mClippingDecorationActors.push_back( actor );
1567 Self().Add( actor );
1572 void TextField::OnStageConnect( Dali::Actor actor )
1574 if ( mHasBeenStaged )
1576 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1580 mHasBeenStaged = true;
1584 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1586 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1587 return mController->OnImfEvent( imfManager, imfEvent );
1590 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1594 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1599 Scripting::CreatePropertyMap( image, map );
1605 void TextField::EnableClipping()
1609 // Creates an extra control to be used as stencil buffer.
1610 mStencil = Control::New();
1611 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1612 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1614 // Creates a background visual. Even if the color is transparent it updates the stencil.
1615 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1616 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1617 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1619 // Enable the clipping property.
1620 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1621 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1623 Self().Add( mStencil );
1627 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1629 mController->PasteClipboardItemEvent();
1632 void TextField::KeyboardStatusChanged(bool keyboardShown)
1634 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1636 // Just hide the grab handle when keyboard is hidden.
1637 if (!keyboardShown )
1639 mController->KeyboardFocusLostEvent();
1643 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1647 void TextField::OnStageConnection( int depth )
1649 // Sets the depth to the visuals inside the text's decorator.
1650 mDecorator->SetTextDepth( depth );
1652 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1654 // Call the Control::OnStageConnection() to set the depth of the background.
1655 Control::OnStageConnection( depth );
1658 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1663 void TextField::OnIdleSignal()
1665 // Emits the change of input style signals.
1666 mController->ProcessInputStyleChangedSignals();
1668 // Set the pointer to null as the callback manager deletes the callback after execute it.
1669 mIdleCallback = NULL;
1672 TextField::TextField()
1673 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1674 mIdleCallback( NULL ),
1675 mAlignmentOffset( 0.f ),
1676 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1677 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1678 mHasBeenStaged( false )
1682 TextField::~TextField()
1684 UnparentAndReset( mStencil );
1686 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1688 Adaptor::Get().RemoveIdle( mIdleCallback );
1692 } // namespace Internal
1694 } // namespace Toolkit