2 * Copyright (c) 2015 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/devel-api/object/type-registry-helper.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/text/rendering-backend.h>
32 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-font-style.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
49 namespace // unnamed namespace
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
56 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 } // unnamed namespace
62 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
64 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
65 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
66 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
68 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
70 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
72 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
73 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
74 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
76 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
81 return Toolkit::TextField::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", STRING, FONT_STYLE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", STRING, INPUT_FONT_STYLE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
127 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
128 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
130 DALI_TYPE_REGISTRATION_END()
134 Toolkit::TextField TextField::New()
136 // Create the implementation, temporarily owned by this handle on stack
137 IntrusivePtr< TextField > impl = new TextField();
139 // Pass ownership to CustomActor handle
140 Toolkit::TextField handle( *impl );
142 // Second-phase init of the implementation
143 // This can only be done after the CustomActor connection has been made...
149 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
151 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
153 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
158 TextField& impl( GetImpl( textField ) );
162 case Toolkit::TextField::Property::RENDERING_BACKEND:
164 int backend = value.Get< int >();
165 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
167 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
168 if( Text::RENDERING_VECTOR_BASED == backend )
170 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
173 if( impl.mRenderingBackend != backend )
175 impl.mRenderingBackend = backend;
176 impl.mRenderer.Reset();
178 if( impl.mController )
180 // When using the vector-based rendering, the size of the GLyphs are different
181 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
182 impl.mController->SetGlyphType( glyphType );
187 case Toolkit::TextField::Property::TEXT:
189 if( impl.mController )
191 const std::string text = value.Get< std::string >();
192 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
194 impl.mController->SetText( text );
198 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
200 if( impl.mController )
202 const std::string text = value.Get< std::string >();
203 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
205 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
209 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
211 if( impl.mController )
213 const std::string text = value.Get< std::string >();
214 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
216 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
220 case Toolkit::TextField::Property::FONT_FAMILY:
222 if( impl.mController )
224 const std::string fontFamily = value.Get< std::string >();
225 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
226 impl.mController->SetDefaultFontFamily( fontFamily );
230 case Toolkit::TextField::Property::FONT_STYLE:
232 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
235 case Toolkit::TextField::Property::POINT_SIZE:
237 if( impl.mController )
239 const float pointSize = value.Get< float >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
242 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
244 impl.mController->SetDefaultPointSize( pointSize );
249 case Toolkit::TextField::Property::MAX_LENGTH:
251 if( impl.mController )
253 const int max = value.Get< int >();
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
256 impl.mController->SetMaximumNumberOfCharacters( max );
260 case Toolkit::TextField::Property::EXCEED_POLICY:
265 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
267 if( impl.mController )
269 const std::string alignStr = value.Get< std::string >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
272 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
273 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
274 HORIZONTAL_ALIGNMENT_STRING_TABLE,
275 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
278 impl.mController->SetHorizontalAlignment( alignment );
283 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
285 if( impl.mController )
287 const std::string alignStr = value.Get< std::string >();
288 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
290 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
291 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
292 VERTICAL_ALIGNMENT_STRING_TABLE,
293 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
296 impl.mController->SetVerticalAlignment( alignment );
301 case Toolkit::TextField::Property::TEXT_COLOR:
303 if( impl.mController )
305 const Vector4 textColor = value.Get< Vector4 >();
306 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 );
308 if( impl.mController->GetTextColor() != textColor )
310 impl.mController->SetTextColor( textColor );
311 impl.mController->SetInputColor( textColor );
312 impl.mRenderer.Reset();
317 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
319 if( impl.mController )
321 const Vector4 textColor = value.Get< Vector4 >();
322 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 );
324 if( impl.mController->GetPlaceholderTextColor() != textColor )
326 impl.mController->SetPlaceholderTextColor( textColor );
327 impl.mRenderer.Reset();
332 case Toolkit::TextField::Property::SHADOW_OFFSET:
334 if( impl.mController )
336 const Vector2 shadowOffset = value.Get< Vector2 >();
337 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
339 if ( impl.mController->GetShadowOffset() != shadowOffset )
341 impl.mController->SetShadowOffset( shadowOffset );
342 impl.mRenderer.Reset();
347 case Toolkit::TextField::Property::SHADOW_COLOR:
349 if( impl.mController )
351 const Vector4 shadowColor = value.Get< Vector4 >();
352 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 );
354 if ( impl.mController->GetShadowColor() != shadowColor )
356 impl.mController->SetShadowColor( shadowColor );
357 impl.mRenderer.Reset();
362 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
364 if( impl.mDecorator )
366 const Vector4 color = value.Get< Vector4 >();
367 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 );
369 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
370 impl.RequestTextRelayout();
374 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
376 if( impl.mDecorator )
378 const Vector4 color = value.Get< Vector4 >();
379 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 );
381 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
382 impl.RequestTextRelayout();
386 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
388 if( impl.mController )
390 const bool enable = value.Get< bool >();
391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
393 impl.mController->SetEnableCursorBlink( enable );
394 impl.RequestTextRelayout();
398 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
400 if( impl.mDecorator )
402 const float interval = value.Get< float >();
403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
405 impl.mDecorator->SetCursorBlinkInterval( interval );
409 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
411 if( impl.mDecorator )
413 const float duration = value.Get< float >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
416 impl.mDecorator->SetCursorBlinkDuration( duration );
420 case Toolkit::TextField::Property::CURSOR_WIDTH:
422 if( impl.mDecorator )
424 const int width = value.Get< int >();
425 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
427 impl.mDecorator->SetCursorWidth( width );
428 impl.mController->GetLayoutEngine().SetCursorWidth( width );
432 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
434 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
435 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
437 if( impl.mDecorator )
439 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
440 impl.RequestTextRelayout();
444 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
446 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
449 if( impl.mDecorator )
451 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
452 impl.RequestTextRelayout();
456 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
458 const float threshold = value.Get< float >();
459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
461 if( impl.mDecorator )
463 impl.mDecorator->SetScrollThreshold( threshold );
467 case Toolkit::TextField::Property::SCROLL_SPEED:
469 const float speed = value.Get< float >();
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
472 if( impl.mDecorator )
474 impl.mDecorator->SetScrollSpeed( speed );
478 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
480 const Image image = Scripting::NewImage( value );
482 if( impl.mDecorator && image )
484 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
485 impl.RequestTextRelayout();
489 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
491 const Image image = Scripting::NewImage( value );
493 if( impl.mDecorator && image )
495 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
496 impl.RequestTextRelayout();
500 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
502 const Image image = Scripting::NewImage( value );
504 if( impl.mDecorator && image )
506 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
507 impl.RequestTextRelayout();
511 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
513 const Image image = Scripting::NewImage( value );
515 if( impl.mDecorator && image )
517 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
518 impl.RequestTextRelayout();
522 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
524 const Image image = Scripting::NewImage( value );
526 if( impl.mDecorator && image )
528 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
529 impl.RequestTextRelayout();
533 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
535 const Image image = Scripting::NewImage( value );
537 if( impl.mDecorator && image )
539 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
540 impl.RequestTextRelayout();
544 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
546 const Vector4 color = value.Get< Vector4 >();
547 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 );
549 if( impl.mDecorator )
551 impl.mDecorator->SetHighlightColor( color );
552 impl.RequestTextRelayout();
556 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
558 if( impl.mDecorator )
560 const Rect<int> box = value.Get< Rect<int> >();
561 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 );
563 impl.mDecorator->SetBoundingBox( box );
564 impl.RequestTextRelayout();
568 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
570 const Property::Map map = value.Get<Property::Map>();
571 VirtualKeyboard::ApplySettings( map );
574 case Toolkit::TextField::Property::INPUT_COLOR:
576 if( impl.mController )
578 const Vector4 inputColor = value.Get< Vector4 >();
579 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 );
581 impl.mController->SetInputColor( inputColor );
585 case Toolkit::TextField::Property::ENABLE_MARKUP:
587 if( impl.mController )
589 const bool enableMarkup = value.Get<bool>();
590 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
592 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
596 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
598 if( impl.mController )
600 const std::string fontFamily = value.Get< std::string >();
601 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
602 impl.mController->SetInputFontFamily( fontFamily );
606 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
608 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
611 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
613 if( impl.mController )
615 const float pointSize = value.Get< float >();
616 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
617 impl.mController->SetInputFontPointSize( pointSize );
625 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
627 Property::Value value;
629 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
633 TextField& impl( GetImpl( textField ) );
637 case Toolkit::TextField::Property::RENDERING_BACKEND:
639 value = impl.mRenderingBackend;
642 case Toolkit::TextField::Property::TEXT:
644 if( impl.mController )
647 impl.mController->GetText( text );
648 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
653 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
655 if( impl.mController )
658 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
663 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
665 if( impl.mController )
668 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
673 case Toolkit::TextField::Property::FONT_FAMILY:
675 if( impl.mController )
677 value = impl.mController->GetDefaultFontFamily();
681 case Toolkit::TextField::Property::FONT_STYLE:
683 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
686 case Toolkit::TextField::Property::POINT_SIZE:
688 if( impl.mController )
690 value = impl.mController->GetDefaultPointSize();
694 case Toolkit::TextField::Property::MAX_LENGTH:
696 if( impl.mController )
698 value = impl.mController->GetMaximumNumberOfCharacters();
702 case Toolkit::TextField::Property::EXCEED_POLICY:
704 value = impl.mExceedPolicy;
707 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
709 if( impl.mController )
711 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
712 HORIZONTAL_ALIGNMENT_STRING_TABLE,
713 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
716 value = std::string( name );
721 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
723 if( impl.mController )
725 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
726 VERTICAL_ALIGNMENT_STRING_TABLE,
727 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
730 value = std::string( name );
735 case Toolkit::TextField::Property::TEXT_COLOR:
737 if ( impl.mController )
739 value = impl.mController->GetTextColor();
743 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
745 if ( impl.mController )
747 value = impl.mController->GetPlaceholderTextColor();
751 case Toolkit::TextField::Property::SHADOW_OFFSET:
753 if ( impl.mController )
755 value = impl.mController->GetShadowOffset();
759 case Toolkit::TextField::Property::SHADOW_COLOR:
761 if ( impl.mController )
763 value = impl.mController->GetShadowColor();
767 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
769 if( impl.mDecorator )
771 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
775 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
777 if( impl.mDecorator )
779 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
783 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
785 value = impl.mController->GetEnableCursorBlink();
788 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
790 if( impl.mDecorator )
792 value = impl.mDecorator->GetCursorBlinkInterval();
796 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
798 if( impl.mDecorator )
800 value = impl.mDecorator->GetCursorBlinkDuration();
804 case Toolkit::TextField::Property::CURSOR_WIDTH:
806 if( impl.mDecorator )
808 value = impl.mDecorator->GetCursorWidth();
812 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
814 if( impl.mDecorator )
816 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
819 value = image.GetUrl();
824 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
826 if( impl.mDecorator )
828 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
831 value = image.GetUrl();
836 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
838 if( impl.mDecorator )
840 value = impl.mDecorator->GetScrollThreshold();
844 case Toolkit::TextField::Property::SCROLL_SPEED:
846 if( impl.mDecorator )
848 value = impl.mDecorator->GetScrollSpeed();
852 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
854 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
857 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
859 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
862 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
864 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
867 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
869 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
872 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
874 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
877 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
879 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
882 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
884 if( impl.mDecorator )
886 value = impl.mDecorator->GetHighlightColor();
890 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
892 if( impl.mDecorator )
894 Rect<int> boundingBox;
895 impl.mDecorator->GetBoundingBox( boundingBox );
900 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
904 case Toolkit::TextField::Property::INPUT_COLOR:
906 if( impl.mController )
908 value = impl.mController->GetInputColor();
912 case Toolkit::TextField::Property::ENABLE_MARKUP:
914 if( impl.mController )
916 value = impl.mController->IsMarkupProcessorEnabled();
920 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
922 if( impl.mController )
924 value = impl.mController->GetInputFontFamily();
928 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
930 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
933 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
935 if( impl.mController )
937 value = impl.mController->GetInputFontPointSize();
947 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
949 Dali::BaseHandle handle( object );
951 bool connected( true );
952 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
954 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
956 field.TextChangedSignal().Connect( tracker, functor );
958 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
960 field.MaxLengthReachedSignal().Connect( tracker, functor );
964 // signalName does not match any signal
971 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
973 return mTextChangedSignal;
976 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
978 return mMaxLengthReachedSignal;
981 void TextField::OnInitialize()
985 mController = Text::Controller::New( *this );
987 // When using the vector-based rendering, the size of the GLyphs are different
988 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
989 mController->SetGlyphType( glyphType );
991 mDecorator = Text::Decorator::New( *mController,
994 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
996 mController->EnableTextInput( mDecorator );
998 // Forward input events to controller
999 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1000 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1002 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1004 // Set BoundingBox to stage size if not already set.
1005 Rect<int> boundingBox;
1006 mDecorator->GetBoundingBox( boundingBox );
1008 if( boundingBox.IsEmpty() )
1010 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1011 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1014 // Flip vertically the 'left' selection handle
1015 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1017 // Fill-parent area by default
1018 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1019 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1020 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1023 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1025 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1029 case StyleChange::DEFAULT_FONT_CHANGE:
1031 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1032 std::string newFont = styleManager.GetDefaultFontFamily();
1033 // Property system did not set the font so should update it.
1034 mController->UpdateAfterFontChange( newFont );
1038 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1040 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
1042 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
1044 // Property system did not set the PointSize so should update it.
1045 // todo instruct text-controller to update model
1049 case StyleChange::THEME_CHANGE:
1051 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1057 Vector3 TextField::GetNaturalSize()
1059 return mController->GetNaturalSize();
1062 float TextField::GetHeightForWidth( float width )
1064 return mController->GetHeightForWidth( width );
1067 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1069 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1071 if( mController->Relayout( size ) ||
1074 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1078 mDecorator->Relayout( size );
1083 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1086 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
1091 void TextField::RenderText()
1093 Actor self = Self();
1094 Actor renderableActor;
1097 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1100 if( renderableActor != mRenderableActor )
1102 UnparentAndReset( mRenderableActor );
1103 mRenderableActor = renderableActor;
1106 if( mRenderableActor )
1108 // TODO: Scroll and alignment needs to be refactored.
1109 const Vector2& alignmentOffset = mController->GetAlignmentOffset();
1110 const Vector2& scrollOffset = mController->GetScrollPosition();
1112 mRenderableActor.SetPosition( scrollOffset.x, alignmentOffset.y + scrollOffset.y );
1114 Actor clipRootActor;
1117 clipRootActor = mClipper->GetRootActor();
1120 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1121 endIt = mClippingDecorationActors.end();
1129 clipRootActor.Add( actor );
1136 mClippingDecorationActors.clear();
1138 // Make sure the actor is parented correctly with/without clipping
1141 clipRootActor.Add( mRenderableActor );
1145 self.Add( mRenderableActor );
1150 void TextField::OnKeyInputFocusGained()
1152 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1154 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1156 ImfManager imfManager = ImfManager::Get();
1160 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1162 // Notify that the text editing start.
1163 imfManager.Activate();
1165 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1166 imfManager.SetRestoreAfterFocusLost( true );
1169 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1173 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1176 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1178 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1181 void TextField::OnKeyInputFocusLost()
1183 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1185 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1187 ImfManager imfManager = ImfManager::Get();
1190 // The text editing is finished. Therefore the imf manager don't have restore activation.
1191 imfManager.SetRestoreAfterFocusLost( false );
1193 // Notify that the text editing finish.
1194 imfManager.Deactivate();
1196 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1199 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1203 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1206 mController->KeyboardFocusLostEvent();
1208 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1211 void TextField::OnTap( const TapGesture& gesture )
1213 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1215 // Show the keyboard if it was hidden.
1216 if (!VirtualKeyboard::IsVisible())
1218 VirtualKeyboard::Show();
1221 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1222 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1227 void TextField::OnPan( const PanGesture& gesture )
1229 mController->PanEvent( gesture.state, gesture.displacement );
1232 void TextField::OnLongPress( const LongPressGesture& gesture )
1234 // Show the keyboard if it was hidden.
1235 if (!VirtualKeyboard::IsVisible())
1237 VirtualKeyboard::Show();
1240 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1245 bool TextField::OnKeyEvent( const KeyEvent& event )
1247 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1249 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1250 "Return" == event.keyPressedName ) // Make a Dali key code for this
1252 ClearKeyInputFocus();
1256 return mController->KeyEvent( event );
1259 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1265 mClippingDecorationActors.push_back( actor );
1269 Self().Add( actor );
1274 void TextField::RequestTextRelayout()
1279 void TextField::TextChanged()
1281 Dali::Toolkit::TextField handle( GetOwner() );
1282 mTextChangedSignal.Emit( handle );
1285 void TextField::OnStageConnect( Dali::Actor actor )
1287 if ( mHasBeenStaged )
1293 mHasBeenStaged = true;
1297 void TextField::MaxLengthReached()
1299 Dali::Toolkit::TextField handle( GetOwner() );
1300 mMaxLengthReachedSignal.Emit( handle );
1303 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1305 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1306 return mController->OnImfEvent( imfManager, imfEvent );
1309 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1313 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1318 Scripting::CreatePropertyMap( image, map );
1324 void TextField::EnableClipping( bool clipping, const Vector2& size )
1328 // Not worth to created clip actor if width or height is equal to zero.
1329 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1333 Actor self = Self();
1335 mClipper = Clipper::New( size );
1336 self.Add( mClipper->GetRootActor() );
1337 self.Add( mClipper->GetImageActor() );
1339 else if ( mClipper )
1341 mClipper->Refresh( size );
1347 // Note - this will automatically remove the root & image actors
1352 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1354 mController->PasteClipboardItemEvent();
1357 void TextField::KeyboardStatusChanged(bool keyboardShown)
1359 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1361 // Just hide the grab handle when keyboard is hidden.
1362 if (!keyboardShown )
1364 mController->KeyboardFocusLostEvent();
1368 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1372 void TextField::OnStageConnection( int depth )
1374 // Call the Control::OnStageConnection() to set the depth of the background.
1375 Control::OnStageConnection( depth );
1377 // Sets the depth to the renderers inside the text's decorator.
1378 mDecorator->SetTextDepth( depth );
1380 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1383 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1388 TextField::TextField()
1389 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1390 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1391 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1392 mHasBeenStaged( false )
1396 TextField::~TextField()
1401 } // namespace Internal
1403 } // namespace Toolkit