2 * Copyright (c) 2016 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/adaptor-framework/virtual-keyboard.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/visuals/visual-properties-devel.h>
36 #include <dali-toolkit/internal/text/rendering/text-backend.h>
37 #include <dali-toolkit/internal/text/text-effects-style.h>
38 #include <dali-toolkit/internal/text/text-font-style.h>
39 #include <dali-toolkit/internal/text/text-view.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 using namespace Dali::Toolkit::Text;
53 namespace // unnamed namespace
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
60 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
61 } // unnamed namespace
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
68 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
69 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
70 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
74 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
76 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
77 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
78 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
80 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
85 return Toolkit::TextField::New();
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
143 DALI_TYPE_REGISTRATION_END()
147 Toolkit::TextField TextField::New()
149 // Create the implementation, temporarily owned by this handle on stack
150 IntrusivePtr< TextField > impl = new TextField();
152 // Pass ownership to CustomActor handle
153 Toolkit::TextField handle( *impl );
155 // Second-phase init of the implementation
156 // This can only be done after the CustomActor connection has been made...
162 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
164 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
166 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
171 TextField& impl( GetImpl( textField ) );
175 case Toolkit::TextField::Property::RENDERING_BACKEND:
177 int backend = value.Get< int >();
178 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
180 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
181 if( Text::RENDERING_VECTOR_BASED == backend )
183 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
186 if( impl.mRenderingBackend != backend )
188 impl.mRenderingBackend = backend;
189 impl.mRenderer.Reset();
191 if( impl.mController )
193 // When using the vector-based rendering, the size of the GLyphs are different
194 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
195 impl.mController->SetGlyphType( glyphType );
200 case Toolkit::TextField::Property::TEXT:
202 if( impl.mController )
204 const std::string& text = value.Get< std::string >();
205 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
207 impl.mController->SetText( text );
211 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
213 if( impl.mController )
215 const std::string& text = value.Get< std::string >();
216 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
218 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
222 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
224 if( impl.mController )
226 const std::string& text = value.Get< std::string >();
227 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
229 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
233 case Toolkit::TextField::Property::FONT_FAMILY:
235 if( impl.mController )
237 const std::string& fontFamily = value.Get< std::string >();
238 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
239 impl.mController->SetDefaultFontFamily( fontFamily );
243 case Toolkit::TextField::Property::FONT_STYLE:
245 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
248 case Toolkit::TextField::Property::POINT_SIZE:
250 if( impl.mController )
252 const float pointSize = value.Get< float >();
253 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
255 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
257 impl.mController->SetDefaultPointSize( pointSize );
262 case Toolkit::TextField::Property::MAX_LENGTH:
264 if( impl.mController )
266 const int max = value.Get< int >();
267 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
269 impl.mController->SetMaximumNumberOfCharacters( max );
273 case Toolkit::TextField::Property::EXCEED_POLICY:
275 impl.mExceedPolicy = value.Get<int>();
277 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
279 impl.EnableClipping();
283 UnparentAndReset( impl.mStencil );
285 impl.RequestTextRelayout();
288 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
290 if( impl.mController )
292 const std::string& alignStr = value.Get< std::string >();
293 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
295 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
296 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
297 HORIZONTAL_ALIGNMENT_STRING_TABLE,
298 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
301 impl.mController->SetHorizontalAlignment( alignment );
306 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
308 if( impl.mController )
310 const std::string& alignStr = value.Get< std::string >();
311 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
313 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
314 if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
315 VERTICAL_ALIGNMENT_STRING_TABLE,
316 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
319 impl.mController->SetVerticalAlignment( alignment );
324 case Toolkit::TextField::Property::TEXT_COLOR:
326 if( impl.mController )
328 const Vector4& textColor = value.Get< Vector4 >();
329 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
331 if( impl.mController->GetDefaultColor() != textColor )
333 impl.mController->SetDefaultColor( textColor );
334 impl.mController->SetInputColor( textColor );
335 impl.mRenderer.Reset();
340 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
342 if( impl.mController )
344 const Vector4& textColor = value.Get< Vector4 >();
345 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
347 if( impl.mController->GetPlaceholderTextColor() != textColor )
349 impl.mController->SetPlaceholderTextColor( textColor );
350 impl.mRenderer.Reset();
355 case Toolkit::TextField::Property::SHADOW_OFFSET:
357 if( impl.mController )
359 const Vector2& shadowOffset = value.Get< Vector2 >();
360 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
362 if ( impl.mController->GetShadowOffset() != shadowOffset )
364 impl.mController->SetShadowOffset( shadowOffset );
365 impl.mRenderer.Reset();
370 case Toolkit::TextField::Property::SHADOW_COLOR:
372 if( impl.mController )
374 const Vector4& shadowColor = value.Get< Vector4 >();
375 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a );
377 if ( impl.mController->GetShadowColor() != shadowColor )
379 impl.mController->SetShadowColor( shadowColor );
380 impl.mRenderer.Reset();
385 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
387 if( impl.mDecorator )
389 const Vector4& color = value.Get< Vector4 >();
390 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
392 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
399 if( impl.mDecorator )
401 const Vector4& color = value.Get< Vector4 >();
402 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
404 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
405 impl.RequestTextRelayout();
409 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
411 if( impl.mController )
413 const bool enable = value.Get< bool >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
416 impl.mController->SetEnableCursorBlink( enable );
417 impl.RequestTextRelayout();
421 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
423 if( impl.mDecorator )
425 const float interval = value.Get< float >();
426 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
428 impl.mDecorator->SetCursorBlinkInterval( interval );
432 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
434 if( impl.mDecorator )
436 const float duration = value.Get< float >();
437 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
439 impl.mDecorator->SetCursorBlinkDuration( duration );
443 case Toolkit::TextField::Property::CURSOR_WIDTH:
445 if( impl.mDecorator )
447 const int width = value.Get< int >();
448 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
450 impl.mDecorator->SetCursorWidth( width );
451 impl.mController->GetLayoutEngine().SetCursorWidth( width );
455 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
457 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
460 if( impl.mDecorator )
462 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
463 impl.RequestTextRelayout();
467 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
469 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
472 if( impl.mDecorator )
474 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
475 impl.RequestTextRelayout();
479 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
481 const float threshold = value.Get< float >();
482 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
484 if( impl.mDecorator )
486 impl.mDecorator->SetScrollThreshold( threshold );
490 case Toolkit::TextField::Property::SCROLL_SPEED:
492 const float speed = value.Get< float >();
493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
495 if( impl.mDecorator )
497 impl.mDecorator->SetScrollSpeed( speed );
501 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
503 const Image image = Scripting::NewImage( value );
505 if( impl.mDecorator && image )
507 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
508 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
514 const Image image = Scripting::NewImage( value );
516 if( impl.mDecorator && image )
518 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
519 impl.RequestTextRelayout();
523 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
525 const Image image = Scripting::NewImage( value );
527 if( impl.mDecorator && image )
529 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
530 impl.RequestTextRelayout();
534 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
536 const Image image = Scripting::NewImage( value );
538 if( impl.mDecorator && image )
540 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
541 impl.RequestTextRelayout();
545 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
547 const Image image = Scripting::NewImage( value );
549 if( impl.mDecorator && image )
551 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
552 impl.RequestTextRelayout();
556 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
558 const Image image = Scripting::NewImage( value );
560 if( impl.mDecorator && image )
562 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
563 impl.RequestTextRelayout();
567 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
569 const Vector4 color = value.Get< Vector4 >();
570 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
572 if( impl.mDecorator )
574 impl.mDecorator->SetHighlightColor( color );
575 impl.RequestTextRelayout();
579 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
581 if( impl.mDecorator )
583 const Rect<int> box = value.Get< Rect<int> >();
584 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
586 impl.mDecorator->SetBoundingBox( box );
587 impl.RequestTextRelayout();
591 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
593 const Property::Map map = value.Get<Property::Map>();
594 VirtualKeyboard::ApplySettings( map );
597 case Toolkit::TextField::Property::INPUT_COLOR:
599 if( impl.mController )
601 const Vector4 inputColor = value.Get< Vector4 >();
602 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 );
604 impl.mController->SetInputColor( inputColor );
608 case Toolkit::TextField::Property::ENABLE_MARKUP:
610 if( impl.mController )
612 const bool enableMarkup = value.Get<bool>();
613 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
615 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
619 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
621 if( impl.mController )
623 const std::string& fontFamily = value.Get< std::string >();
624 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
625 impl.mController->SetInputFontFamily( fontFamily );
629 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
631 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
634 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
636 if( impl.mController )
638 const float pointSize = value.Get< float >();
639 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
640 impl.mController->SetInputFontPointSize( pointSize );
644 case Toolkit::TextField::Property::UNDERLINE:
646 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
649 impl.mRenderer.Reset();
653 case Toolkit::TextField::Property::INPUT_UNDERLINE:
655 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
658 impl.mRenderer.Reset();
662 case Toolkit::TextField::Property::SHADOW:
664 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
667 impl.mRenderer.Reset();
671 case Toolkit::TextField::Property::INPUT_SHADOW:
673 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
676 impl.mRenderer.Reset();
680 case Toolkit::TextField::Property::EMBOSS:
682 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
685 impl.mRenderer.Reset();
689 case Toolkit::TextField::Property::INPUT_EMBOSS:
691 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
694 impl.mRenderer.Reset();
698 case Toolkit::TextField::Property::OUTLINE:
700 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
703 impl.mRenderer.Reset();
707 case Toolkit::TextField::Property::INPUT_OUTLINE:
709 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
712 impl.mRenderer.Reset();
720 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
722 Property::Value value;
724 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
728 TextField& impl( GetImpl( textField ) );
732 case Toolkit::TextField::Property::RENDERING_BACKEND:
734 value = impl.mRenderingBackend;
737 case Toolkit::TextField::Property::TEXT:
739 if( impl.mController )
742 impl.mController->GetText( text );
743 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
748 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
750 if( impl.mController )
753 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
758 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
760 if( impl.mController )
763 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
768 case Toolkit::TextField::Property::FONT_FAMILY:
770 if( impl.mController )
772 value = impl.mController->GetDefaultFontFamily();
776 case Toolkit::TextField::Property::FONT_STYLE:
778 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
781 case Toolkit::TextField::Property::POINT_SIZE:
783 if( impl.mController )
785 value = impl.mController->GetDefaultPointSize();
789 case Toolkit::TextField::Property::MAX_LENGTH:
791 if( impl.mController )
793 value = impl.mController->GetMaximumNumberOfCharacters();
797 case Toolkit::TextField::Property::EXCEED_POLICY:
799 value = impl.mExceedPolicy;
802 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
804 if( impl.mController )
806 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
807 HORIZONTAL_ALIGNMENT_STRING_TABLE,
808 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
811 value = std::string( name );
816 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
818 if( impl.mController )
820 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
821 VERTICAL_ALIGNMENT_STRING_TABLE,
822 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
825 value = std::string( name );
830 case Toolkit::TextField::Property::TEXT_COLOR:
832 if ( impl.mController )
834 value = impl.mController->GetDefaultColor();
838 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
840 if ( impl.mController )
842 value = impl.mController->GetPlaceholderTextColor();
846 case Toolkit::TextField::Property::SHADOW_OFFSET:
848 if ( impl.mController )
850 value = impl.mController->GetShadowOffset();
854 case Toolkit::TextField::Property::SHADOW_COLOR:
856 if ( impl.mController )
858 value = impl.mController->GetShadowColor();
862 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
864 if( impl.mDecorator )
866 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
870 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
872 if( impl.mDecorator )
874 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
878 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
880 value = impl.mController->GetEnableCursorBlink();
883 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
885 if( impl.mDecorator )
887 value = impl.mDecorator->GetCursorBlinkInterval();
891 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
893 if( impl.mDecorator )
895 value = impl.mDecorator->GetCursorBlinkDuration();
899 case Toolkit::TextField::Property::CURSOR_WIDTH:
901 if( impl.mDecorator )
903 value = impl.mDecorator->GetCursorWidth();
907 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
909 if( impl.mDecorator )
911 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
914 value = image.GetUrl();
919 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
921 if( impl.mDecorator )
923 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
926 value = image.GetUrl();
931 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
933 if( impl.mDecorator )
935 value = impl.mDecorator->GetScrollThreshold();
939 case Toolkit::TextField::Property::SCROLL_SPEED:
941 if( impl.mDecorator )
943 value = impl.mDecorator->GetScrollSpeed();
947 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
949 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
952 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
954 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
957 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
959 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
962 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
964 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
967 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
969 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
972 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
974 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
977 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
979 if( impl.mDecorator )
981 value = impl.mDecorator->GetHighlightColor();
985 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
987 if( impl.mDecorator )
989 Rect<int> boundingBox;
990 impl.mDecorator->GetBoundingBox( boundingBox );
995 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
999 case Toolkit::TextField::Property::INPUT_COLOR:
1001 if( impl.mController )
1003 value = impl.mController->GetInputColor();
1007 case Toolkit::TextField::Property::ENABLE_MARKUP:
1009 if( impl.mController )
1011 value = impl.mController->IsMarkupProcessorEnabled();
1015 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1017 if( impl.mController )
1019 value = impl.mController->GetInputFontFamily();
1023 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1025 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1028 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1030 if( impl.mController )
1032 value = impl.mController->GetInputFontPointSize();
1036 case Toolkit::TextField::Property::UNDERLINE:
1038 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1041 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1043 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1046 case Toolkit::TextField::Property::SHADOW:
1048 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1051 case Toolkit::TextField::Property::INPUT_SHADOW:
1053 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1056 case Toolkit::TextField::Property::EMBOSS:
1058 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1061 case Toolkit::TextField::Property::INPUT_EMBOSS:
1063 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1066 case Toolkit::TextField::Property::OUTLINE:
1068 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1071 case Toolkit::TextField::Property::INPUT_OUTLINE:
1073 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1082 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1084 Dali::BaseHandle handle( object );
1086 bool connected( true );
1087 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1089 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1091 field.TextChangedSignal().Connect( tracker, functor );
1093 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1095 field.MaxLengthReachedSignal().Connect( tracker, functor );
1097 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1099 field.InputStyleChangedSignal().Connect( tracker, functor );
1103 // signalName does not match any signal
1110 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1112 return mTextChangedSignal;
1115 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1117 return mMaxLengthReachedSignal;
1120 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1122 return mInputStyleChangedSignal;
1125 void TextField::OnInitialize()
1127 Actor self = Self();
1129 mController = Text::Controller::New( this, this );
1131 // When using the vector-based rendering, the size of the GLyphs are different
1132 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1133 mController->SetGlyphType( glyphType );
1135 mDecorator = Text::Decorator::New( *mController,
1138 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1140 // Enables the text input.
1141 mController->EnableTextInput( mDecorator );
1143 // Enables the horizontal scrolling after the text input has been enabled.
1144 mController->SetHorizontalScrollEnabled( true );
1146 // Disables the vertical scrolling.
1147 mController->SetVerticalScrollEnabled( false );
1149 // Disable the smooth handle panning.
1150 mController->SetSmoothHandlePanEnabled( false );
1152 // Forward input events to controller
1153 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1154 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1156 self.TouchSignal().Connect( this, &TextField::OnTouched );
1158 // Set BoundingBox to stage size if not already set.
1159 Rect<int> boundingBox;
1160 mDecorator->GetBoundingBox( boundingBox );
1162 if( boundingBox.IsEmpty() )
1164 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1165 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1168 // Flip vertically the 'left' selection handle
1169 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1171 // Fill-parent area by default
1172 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1173 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1174 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1176 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1182 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1188 case StyleChange::DEFAULT_FONT_CHANGE:
1190 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1191 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1192 // Property system did not set the font so should update it.
1193 mController->UpdateAfterFontChange( newFont );
1197 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1199 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1202 case StyleChange::THEME_CHANGE:
1204 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1210 Vector3 TextField::GetNaturalSize()
1212 return mController->GetNaturalSize();
1215 float TextField::GetHeightForWidth( float width )
1217 return mController->GetHeightForWidth( width );
1220 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1222 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1224 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1226 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1229 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1232 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1234 mDecorator->Relayout( size );
1239 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1242 RenderText( updateTextType );
1245 // The text-field emits signals when the input style changes. These changes of style are
1246 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1247 // can't be emitted during the size negotiation as the callbacks may update the UI.
1248 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1249 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1251 if( Adaptor::IsAvailable() )
1253 Adaptor& adaptor = Adaptor::Get();
1255 if( NULL == mIdleCallback )
1257 // @note: The callback manager takes the ownership of the callback object.
1258 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1259 adaptor.AddIdle( mIdleCallback );
1265 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1267 Actor renderableActor;
1269 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1273 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1276 if( renderableActor != mRenderableActor )
1278 UnparentAndReset( mRenderableActor );
1279 mRenderableActor = renderableActor;
1283 if( mRenderableActor )
1285 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1287 mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
1289 // Make sure the actors are parented correctly with/without clipping
1290 Actor self = mStencil ? mStencil : Self();
1292 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1293 endIt = mClippingDecorationActors.end();
1299 mClippingDecorationActors.clear();
1301 self.Add( mRenderableActor );
1305 void TextField::OnKeyInputFocusGained()
1307 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1309 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1311 ImfManager imfManager = ImfManager::Get();
1315 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1317 // Notify that the text editing start.
1318 imfManager.Activate();
1320 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1321 imfManager.SetRestoreAfterFocusLost( true );
1324 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1328 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1331 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1333 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1336 void TextField::OnKeyInputFocusLost()
1338 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1340 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1342 ImfManager imfManager = ImfManager::Get();
1345 // The text editing is finished. Therefore the imf manager don't have restore activation.
1346 imfManager.SetRestoreAfterFocusLost( false );
1348 // Notify that the text editing finish.
1349 imfManager.Deactivate();
1351 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1354 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1358 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1361 mController->KeyboardFocusLostEvent();
1363 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1366 void TextField::OnTap( const TapGesture& gesture )
1368 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1370 // Show the keyboard if it was hidden.
1371 if (!VirtualKeyboard::IsVisible())
1373 VirtualKeyboard::Show();
1376 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1377 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1382 void TextField::OnPan( const PanGesture& gesture )
1384 mController->PanEvent( gesture.state, gesture.displacement );
1387 void TextField::OnLongPress( const LongPressGesture& gesture )
1389 // Show the keyboard if it was hidden.
1390 if (!VirtualKeyboard::IsVisible())
1392 VirtualKeyboard::Show();
1395 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1400 bool TextField::OnKeyEvent( const KeyEvent& event )
1402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1404 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1405 "Return" == event.keyPressedName ) // Make a Dali key code for this
1407 ClearKeyInputFocus();
1411 return mController->KeyEvent( event );
1414 void TextField::RequestTextRelayout()
1419 void TextField::TextChanged()
1421 Dali::Toolkit::TextField handle( GetOwner() );
1422 mTextChangedSignal.Emit( handle );
1425 void TextField::MaxLengthReached()
1427 Dali::Toolkit::TextField handle( GetOwner() );
1428 mMaxLengthReachedSignal.Emit( handle );
1431 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1433 Dali::Toolkit::TextField handle( GetOwner() );
1435 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1437 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1439 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1441 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1443 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1445 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1447 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1449 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1451 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1453 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1455 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1457 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1459 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1461 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1463 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1465 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1467 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1469 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1471 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1473 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1475 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1478 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1481 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1487 mClippingDecorationActors.push_back( actor );
1491 Self().Add( actor );
1496 void TextField::OnStageConnect( Dali::Actor actor )
1498 if ( mHasBeenStaged )
1500 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1504 mHasBeenStaged = true;
1508 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1510 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1511 return mController->OnImfEvent( imfManager, imfEvent );
1514 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1518 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1523 Scripting::CreatePropertyMap( image, map );
1529 void TextField::EnableClipping()
1533 // Creates an extra control to be used as stencil buffer.
1534 mStencil = Control::New();
1535 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1536 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1538 // Creates a background visual. Even if the color is transparent it updates the stencil.
1539 // Property::Map backgroundMap;
1540 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1541 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1542 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1544 // Enable the clipping property.
1545 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1546 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1548 Self().Add( mStencil );
1552 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1554 mController->PasteClipboardItemEvent();
1557 void TextField::KeyboardStatusChanged(bool keyboardShown)
1559 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1561 // Just hide the grab handle when keyboard is hidden.
1562 if (!keyboardShown )
1564 mController->KeyboardFocusLostEvent();
1568 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1572 void TextField::OnStageConnection( int depth )
1574 // Call the Control::OnStageConnection() to set the depth of the background.
1575 Control::OnStageConnection( depth );
1577 // Sets the depth to the visuals inside the text's decorator.
1578 mDecorator->SetTextDepth( depth );
1580 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1583 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1588 void TextField::OnIdleSignal()
1590 // Emits the change of input style signals.
1591 mController->ProcessInputStyleChangedSignals();
1593 // Set the pointer to null as the callback manager deletes the callback after execute it.
1594 mIdleCallback = NULL;
1597 TextField::TextField()
1598 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1599 mIdleCallback( NULL ),
1600 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1601 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1602 mHasBeenStaged( false )
1606 TextField::~TextField()
1608 UnparentAndReset( mStencil );
1610 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1612 Adaptor::Get().RemoveIdle( mIdleCallback );
1616 } // namespace Internal
1618 } // namespace Toolkit