2 * Copyright (c) 2020 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/dali-common.h>
25 #include <dali/devel-api/adaptor-framework/key-devel.h>
26 #include <dali/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
48 #include <dali/integration-api/adaptor-framework/adaptor.h>
50 using namespace Dali::Toolkit::Text;
61 namespace // unnamed namespace
64 #if defined(DEBUG_ENABLED)
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
68 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
69 } // unnamed namespace
76 return Toolkit::TextField::New();
79 // Setup properties, signals and actions using the type-registry.
80 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
136 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
146 DALI_TYPE_REGISTRATION_END()
148 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
150 /// Retrieves a filename from a value that is a Property::Map
151 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
153 std::string filename;
154 const Property::Map* map = value.GetMap();
157 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
160 filenameValue->Get( filename );
168 Toolkit::TextField TextField::New()
170 // Create the implementation, temporarily owned by this handle on stack
171 IntrusivePtr< TextField > impl = new TextField();
173 // Pass ownership to CustomActor handle
174 Toolkit::TextField handle( *impl );
176 // Second-phase init of the implementation
177 // This can only be done after the CustomActor connection has been made...
183 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
185 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
187 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
191 TextField& impl( GetImpl( textField ) );
192 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
193 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
197 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
199 int backend = value.Get< int >();
200 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
202 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
203 if( DevelText::RENDERING_VECTOR_BASED == backend )
205 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
208 if( impl.mRenderingBackend != backend )
210 impl.mRenderingBackend = backend;
211 impl.mRenderer.Reset();
213 // When using the vector-based rendering, the size of the GLyphs are different
214 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
215 impl.mController->SetGlyphType( glyphType );
219 case Toolkit::TextField::Property::TEXT:
221 const std::string& text = value.Get< std::string >();
222 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
224 impl.mController->SetText( text );
227 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
229 const std::string& text = value.Get< std::string >();
230 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
232 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
235 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
237 const std::string& text = value.Get< std::string >();
238 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
240 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
243 case Toolkit::TextField::Property::FONT_FAMILY:
245 const std::string& fontFamily = value.Get< std::string >();
246 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
247 impl.mController->SetDefaultFontFamily( fontFamily );
250 case Toolkit::TextField::Property::FONT_STYLE:
252 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
255 case Toolkit::TextField::Property::POINT_SIZE:
257 const float pointSize = value.Get< float >();
258 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
260 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
262 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
266 case Toolkit::TextField::Property::MAX_LENGTH:
268 const int max = value.Get< int >();
269 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
271 impl.mController->SetMaximumNumberOfCharacters( max );
274 case Toolkit::TextField::Property::EXCEED_POLICY:
276 impl.mExceedPolicy = value.Get<int>();
278 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
280 impl.EnableClipping();
284 UnparentAndReset( impl.mStencil );
286 impl.RequestTextRelayout();
289 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
291 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
292 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
294 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
295 impl.mController->SetHorizontalAlignment( alignment );
299 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
301 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
302 if( GetVerticalAlignmentEnumeration( value, alignment ) )
304 impl.mController->SetVerticalAlignment( alignment );
305 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
309 case Toolkit::TextField::Property::TEXT_COLOR:
311 const Vector4& textColor = value.Get< Vector4 >();
312 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 );
314 if( impl.mController->GetDefaultColor() != textColor )
316 impl.mController->SetDefaultColor( textColor );
317 impl.mController->SetInputColor( textColor );
318 impl.mRenderer.Reset();
322 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
324 const Vector4& textColor = value.Get< Vector4 >();
325 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 );
327 if( impl.mController->GetPlaceholderTextColor() != textColor )
329 impl.mController->SetPlaceholderTextColor( textColor );
330 impl.mRenderer.Reset();
334 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
336 const Vector4& color = value.Get< Vector4 >();
337 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 );
339 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
340 impl.RequestTextRelayout();
343 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
345 const Vector4& color = value.Get< Vector4 >();
346 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 );
348 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
349 impl.RequestTextRelayout();
352 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
354 const bool enable = value.Get< bool >();
355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
357 impl.mController->SetEnableCursorBlink( enable );
358 impl.RequestTextRelayout();
361 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
363 const float interval = value.Get< float >();
364 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
366 impl.mDecorator->SetCursorBlinkInterval( interval );
369 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
371 const float duration = value.Get< float >();
372 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
374 impl.mDecorator->SetCursorBlinkDuration( duration );
377 case Toolkit::TextField::Property::CURSOR_WIDTH:
379 const int width = value.Get< int >();
380 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
382 impl.mDecorator->SetCursorWidth( width );
383 impl.mController->GetLayoutEngine().SetCursorWidth( width );
386 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
388 const std::string imageFileName = value.Get< std::string >();
389 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
391 if( imageFileName.size() )
393 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
394 impl.RequestTextRelayout();
398 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
400 const std::string imageFileName = value.Get< std::string >();
401 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
403 if( imageFileName.size() )
405 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
406 impl.RequestTextRelayout();
410 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
412 const float threshold = value.Get< float >();
413 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
415 impl.mDecorator->SetScrollThreshold( threshold );
418 case Toolkit::TextField::Property::SCROLL_SPEED:
420 const float speed = value.Get< float >();
421 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
423 impl.mDecorator->SetScrollSpeed( speed );
426 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
428 const std::string filename = GetImageFileNameFromPropertyValue( value );
430 if( filename.size() )
432 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
433 impl.RequestTextRelayout();
437 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
439 const std::string filename = GetImageFileNameFromPropertyValue( value );
441 if( filename.size() )
443 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
444 impl.RequestTextRelayout();
448 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
450 const std::string filename = GetImageFileNameFromPropertyValue( value );
452 if( filename.size() )
454 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
455 impl.RequestTextRelayout();
459 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
461 const std::string filename = GetImageFileNameFromPropertyValue( value );
463 if( filename.size() )
465 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
466 impl.RequestTextRelayout();
470 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
472 const std::string filename = GetImageFileNameFromPropertyValue( value );
474 if( filename.size() )
476 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
477 impl.RequestTextRelayout();
481 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
483 const std::string filename = GetImageFileNameFromPropertyValue( value );
485 if( filename.size() )
487 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
488 impl.RequestTextRelayout();
492 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
494 const Vector4 color = value.Get< Vector4 >();
495 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 );
497 impl.mDecorator->SetHighlightColor( color );
498 impl.RequestTextRelayout();
501 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
503 const Rect<int> box = value.Get< Rect<int> >();
504 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 );
506 impl.mDecorator->SetBoundingBox( box );
507 impl.RequestTextRelayout();
510 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
512 const Property::Map* map = value.GetMap();
515 impl.mInputMethodOptions.ApplyProperty( *map );
517 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
519 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
520 if (control == textField)
522 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
526 case Toolkit::TextField::Property::INPUT_COLOR:
528 const Vector4 inputColor = value.Get< Vector4 >();
529 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 );
531 impl.mController->SetInputColor( inputColor );
534 case Toolkit::TextField::Property::ENABLE_MARKUP:
536 const bool enableMarkup = value.Get<bool>();
537 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
539 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
542 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
544 const std::string& fontFamily = value.Get< std::string >();
545 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
546 impl.mController->SetInputFontFamily( fontFamily );
549 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
551 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
554 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
556 const float pointSize = value.Get< float >();
557 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
558 impl.mController->SetInputFontPointSize( pointSize );
561 case Toolkit::TextField::Property::UNDERLINE:
563 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
566 impl.mRenderer.Reset();
570 case Toolkit::TextField::Property::INPUT_UNDERLINE:
572 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
575 impl.mRenderer.Reset();
579 case Toolkit::TextField::Property::SHADOW:
581 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
584 impl.mRenderer.Reset();
588 case Toolkit::TextField::Property::INPUT_SHADOW:
590 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
593 impl.mRenderer.Reset();
597 case Toolkit::TextField::Property::EMBOSS:
599 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
602 impl.mRenderer.Reset();
606 case Toolkit::TextField::Property::INPUT_EMBOSS:
608 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
611 impl.mRenderer.Reset();
615 case Toolkit::TextField::Property::OUTLINE:
617 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
620 impl.mRenderer.Reset();
624 case Toolkit::TextField::Property::INPUT_OUTLINE:
626 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
629 impl.mRenderer.Reset();
633 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
635 const Property::Map* map = value.GetMap();
638 impl.mController->SetHiddenInputOption(*map);
642 case Toolkit::TextField::Property::PIXEL_SIZE:
644 const float pixelSize = value.Get< float >();
645 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
647 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
649 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
653 case Toolkit::TextField::Property::ENABLE_SELECTION:
655 const bool enableSelection = value.Get< bool >();
656 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
657 impl.mController->SetSelectionEnabled( enableSelection );
660 case Toolkit::TextField::Property::PLACEHOLDER:
662 const Property::Map* map = value.GetMap();
665 impl.mController->SetPlaceholderProperty( *map );
669 case Toolkit::TextField::Property::ELLIPSIS:
671 const bool ellipsis = value.Get<bool>();
672 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
674 impl.mController->SetTextElideEnabled( ellipsis );
677 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
679 const bool shiftSelection = value.Get<bool>();
680 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
682 impl.mController->SetShiftSelectionEnabled( shiftSelection );
685 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
687 const bool grabHandleEnabled = value.Get<bool>();
688 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
690 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
693 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
695 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
698 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
700 const bool grabHandlePopupEnabled = value.Get<bool>();
701 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
703 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
706 case Toolkit::DevelTextField::Property::BACKGROUND:
708 const Vector4 backgroundColor = value.Get< Vector4 >();
709 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a );
711 impl.mController->SetBackgroundEnabled( true );
712 impl.mController->SetBackgroundColor( backgroundColor );
715 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
717 if( impl.mController )
719 uint32_t start = static_cast<uint32_t>(value.Get< int >());
720 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
721 impl.SetTextSelectionRange( &start, nullptr );
725 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
727 if( impl.mController )
729 uint32_t end = static_cast<uint32_t>(value.Get< int >());
730 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
731 impl.SetTextSelectionRange( nullptr, &end );
735 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
737 const bool editable = value.Get< bool >();
738 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
739 impl.SetEditable( editable );
746 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
748 Property::Value value;
750 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
754 TextField& impl( GetImpl( textField ) );
755 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
756 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
760 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
762 value = impl.mRenderingBackend;
765 case Toolkit::TextField::Property::TEXT:
768 impl.mController->GetText( text );
769 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
773 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
776 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
780 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
783 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
787 case Toolkit::TextField::Property::FONT_FAMILY:
789 value = impl.mController->GetDefaultFontFamily();
792 case Toolkit::TextField::Property::FONT_STYLE:
794 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
797 case Toolkit::TextField::Property::POINT_SIZE:
799 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
802 case Toolkit::TextField::Property::MAX_LENGTH:
804 value = impl.mController->GetMaximumNumberOfCharacters();
807 case Toolkit::TextField::Property::EXCEED_POLICY:
809 value = impl.mExceedPolicy;
812 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
814 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
818 value = std::string( name );
822 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
824 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
828 value = std::string( name );
832 case Toolkit::TextField::Property::TEXT_COLOR:
834 value = impl.mController->GetDefaultColor();
837 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
839 value = impl.mController->GetPlaceholderTextColor();
842 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
844 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
847 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
849 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
852 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
854 value = impl.mController->GetEnableCursorBlink();
857 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
859 value = impl.mDecorator->GetCursorBlinkInterval();
862 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
864 value = impl.mDecorator->GetCursorBlinkDuration();
867 case Toolkit::TextField::Property::CURSOR_WIDTH:
869 value = impl.mDecorator->GetCursorWidth();
872 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
874 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
877 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
879 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
882 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
884 value = impl.mDecorator->GetScrollThreshold();
887 case Toolkit::TextField::Property::SCROLL_SPEED:
889 value = impl.mDecorator->GetScrollSpeed();
892 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
894 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
897 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
899 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
902 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
904 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
907 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
909 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
912 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
914 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
917 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
919 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
922 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
924 value = impl.mDecorator->GetHighlightColor();
927 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
929 Rect<int> boundingBox;
930 impl.mDecorator->GetBoundingBox( boundingBox );
934 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
937 impl.mInputMethodOptions.RetrieveProperty( map );
941 case Toolkit::TextField::Property::INPUT_COLOR:
943 value = impl.mController->GetInputColor();
946 case Toolkit::TextField::Property::ENABLE_MARKUP:
948 value = impl.mController->IsMarkupProcessorEnabled();
951 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
953 value = impl.mController->GetInputFontFamily();
956 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
958 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
961 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
963 value = impl.mController->GetInputFontPointSize();
966 case Toolkit::TextField::Property::UNDERLINE:
968 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
971 case Toolkit::TextField::Property::INPUT_UNDERLINE:
973 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
976 case Toolkit::TextField::Property::SHADOW:
978 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
981 case Toolkit::TextField::Property::INPUT_SHADOW:
983 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
986 case Toolkit::TextField::Property::EMBOSS:
988 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
991 case Toolkit::TextField::Property::INPUT_EMBOSS:
993 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
996 case Toolkit::TextField::Property::OUTLINE:
998 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1001 case Toolkit::TextField::Property::INPUT_OUTLINE:
1003 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1006 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1009 impl.mController->GetHiddenInputOption(map);
1013 case Toolkit::TextField::Property::PIXEL_SIZE:
1015 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1018 case Toolkit::TextField::Property::ENABLE_SELECTION:
1020 value = impl.mController->IsSelectionEnabled();
1023 case Toolkit::TextField::Property::PLACEHOLDER:
1026 impl.mController->GetPlaceholderProperty( map );
1030 case Toolkit::TextField::Property::ELLIPSIS:
1032 value = impl.mController->IsTextElideEnabled();
1035 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1037 value = impl.mController->IsShiftSelectionEnabled();
1040 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1042 value = impl.mController->IsGrabHandleEnabled();
1045 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1047 value = impl.mController->IsMatchSystemLanguageDirection();
1050 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1052 value = impl.mController->IsGrabHandlePopupEnabled();
1055 case Toolkit::DevelTextField::Property::BACKGROUND:
1057 value = impl.mController->GetBackgroundColor();
1060 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1062 value = impl.mController->GetSelectedText( );
1065 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1067 Uint32Pair range = impl.GetTextSelectionRange( );
1068 value = static_cast<int>(range.first);
1071 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1073 Uint32Pair range = impl.GetTextSelectionRange( );
1074 value = static_cast<int>(range.second);
1077 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1079 value = impl.IsEditable();
1088 void TextField::SelectWholeText()
1090 if( mController && mController->IsShowingRealText() )
1092 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1097 void TextField::SelectNone()
1099 if( mController && mController->IsShowingRealText() )
1101 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1106 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1108 if( mController && mController->IsShowingRealText() )
1110 mController->SetTextSelectionRange( start, end );
1115 Uint32Pair TextField::GetTextSelectionRange() const
1118 if( mController && mController->IsShowingRealText() )
1120 range = mController->GetTextSelectionRange();
1126 InputMethodContext TextField::GetInputMethodContext()
1128 return mInputMethodContext;
1131 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1133 Dali::BaseHandle handle( object );
1135 bool connected( true );
1136 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1138 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1140 field.TextChangedSignal().Connect( tracker, functor );
1142 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1144 field.MaxLengthReachedSignal().Connect( tracker, functor );
1146 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1148 field.InputStyleChangedSignal().Connect( tracker, functor );
1152 // signalName does not match any signal
1159 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1161 return mTextChangedSignal;
1164 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1166 return mMaxLengthReachedSignal;
1169 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1171 return mInputStyleChangedSignal;
1174 void TextField::OnInitialize()
1176 Actor self = Self();
1178 mController = Text::Controller::New( this, this ,this);
1180 // When using the vector-based rendering, the size of the GLyphs are different
1181 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1182 mController->SetGlyphType( glyphType );
1184 mDecorator = Text::Decorator::New( *mController,
1187 mInputMethodContext = InputMethodContext::New( self );
1189 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1191 // Enables the text input.
1192 mController->EnableTextInput( mDecorator, mInputMethodContext );
1194 // Enables the horizontal scrolling after the text input has been enabled.
1195 mController->SetHorizontalScrollEnabled( true );
1197 // Disables the vertical scrolling.
1198 mController->SetVerticalScrollEnabled( false );
1200 // Disable the smooth handle panning.
1201 mController->SetSmoothHandlePanEnabled( false );
1203 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1204 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1206 // Sets layoutDirection value
1207 Dali::Stage stage = Dali::Stage::GetCurrent();
1208 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1209 mController->SetLayoutDirection( layoutDirection );
1211 // Forward input events to controller
1212 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1213 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1215 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1217 // Set BoundingBox to stage size if not already set.
1218 Rect<int> boundingBox;
1219 mDecorator->GetBoundingBox( boundingBox );
1221 if( boundingBox.IsEmpty() )
1223 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1224 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1227 // Flip vertically the 'left' selection handle
1228 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1230 // Fill-parent area by default
1231 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1232 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1233 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1235 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1237 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1243 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1245 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1249 case StyleChange::DEFAULT_FONT_CHANGE:
1251 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1252 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1253 // Property system did not set the font so should update it.
1254 mController->UpdateAfterFontChange( newFont );
1259 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1261 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1265 case StyleChange::THEME_CHANGE:
1267 // Nothing to do, let control base class handle this
1272 // Up call to Control
1273 Control::OnStyleChange( styleManager, change );
1276 Vector3 TextField::GetNaturalSize()
1279 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1281 Vector3 naturalSize = mController->GetNaturalSize();
1282 naturalSize.width += ( padding.start + padding.end );
1283 naturalSize.height += ( padding.top + padding.bottom );
1288 float TextField::GetHeightForWidth( float width )
1291 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1292 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1295 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1297 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1299 Actor self = Self();
1302 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1304 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1306 // Support Right-To-Left of padding
1307 Dali::LayoutDirection::Type layoutDirection;
1308 if( mController->IsMatchSystemLanguageDirection() )
1310 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1314 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1316 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1318 std::swap( padding.start, padding.end );
1323 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1327 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1330 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1332 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1335 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1338 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1340 mDecorator->Relayout( size );
1345 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1348 RenderText( updateTextType );
1352 // The text-field emits signals when the input style changes. These changes of style are
1353 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1354 // can't be emitted during the size negotiation as the callbacks may update the UI.
1355 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1356 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1358 if( Adaptor::IsAvailable() )
1360 Adaptor& adaptor = Adaptor::Get();
1362 if( NULL == mIdleCallback )
1364 // @note: The callback manager takes the ownership of the callback object.
1365 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1366 adaptor.AddIdle( mIdleCallback, false );
1372 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1374 Actor renderableActor;
1376 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1380 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1382 renderableActor = mRenderer->Render( mController->GetView(),
1384 Property::INVALID_INDEX, // Animatable property not supported
1386 DepthIndex::CONTENT );
1389 if( renderableActor != mRenderableActor )
1391 UnparentAndReset( mBackgroundActor );
1392 UnparentAndReset( mRenderableActor );
1393 mRenderableActor = renderableActor;
1395 if ( mRenderableActor )
1397 mBackgroundActor = mController->CreateBackgroundActor();
1402 if( mRenderableActor )
1404 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1406 float renderableActorPositionX, renderableActorPositionY;
1410 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1411 renderableActorPositionY = scrollOffset.y;
1416 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1418 // Support Right-To-Left of padding
1419 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1420 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1422 std::swap( padding.start, padding.end );
1425 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1426 renderableActorPositionY = scrollOffset.y + padding.top;
1429 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1431 // Make sure the actors are parented correctly with/without clipping
1432 Actor self = mStencil ? mStencil : Self();
1434 Actor highlightActor;
1436 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1437 endIt = mClippingDecorationActors.end();
1442 it->LowerToBottom();
1444 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1446 highlightActor = *it;
1449 mClippingDecorationActors.clear();
1451 self.Add( mRenderableActor );
1453 if ( mBackgroundActor )
1455 if ( mDecorator && mDecorator->IsHighlightVisible() )
1457 self.Add( mBackgroundActor );
1458 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1459 mBackgroundActor.LowerBelow( highlightActor );
1463 mRenderableActor.Add( mBackgroundActor );
1464 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1465 mBackgroundActor.LowerToBottom();
1471 void TextField::OnKeyInputFocusGained()
1473 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1474 if ( mInputMethodContext && IsEditable() )
1476 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1478 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1480 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1482 // Notify that the text editing start.
1483 mInputMethodContext.Activate();
1485 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1486 mInputMethodContext.SetRestoreAfterFocusLost( true );
1488 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1492 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1495 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1497 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1500 void TextField::OnKeyInputFocusLost()
1502 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1503 if ( mInputMethodContext )
1505 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1506 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1507 mInputMethodContext.SetRestoreAfterFocusLost( false );
1509 // Notify that the text editing finish.
1510 mInputMethodContext.Deactivate();
1512 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1514 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1518 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1521 mController->KeyboardFocusLostEvent();
1523 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1526 void TextField::OnTap( const TapGesture& gesture )
1528 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1529 if ( mInputMethodContext && IsEditable() )
1531 mInputMethodContext.Activate();
1533 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1535 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1536 const Vector2& localPoint = gesture.GetLocalPoint();
1537 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1542 void TextField::OnPan( const PanGesture& gesture )
1544 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1547 void TextField::OnLongPress( const LongPressGesture& gesture )
1549 if ( mInputMethodContext && IsEditable() )
1551 mInputMethodContext.Activate();
1554 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1555 const Vector2& localPoint = gesture.GetLocalPoint();
1556 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1561 bool TextField::OnKeyEvent( const KeyEvent& event )
1563 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1565 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1567 // Make sure ClearKeyInputFocus when only key is up
1568 if( event.GetState() == KeyEvent::UP )
1570 ClearKeyInputFocus();
1575 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1577 // Do nothing when enter is comming.
1581 return mController->KeyEvent( event );
1584 void TextField::RequestTextRelayout()
1589 bool TextField::IsEditable() const
1591 return mController->IsEditable();
1594 void TextField::SetEditable( bool editable )
1596 mController->SetEditable(editable);
1597 if ( mInputMethodContext && !editable )
1599 mInputMethodContext.Deactivate();
1603 void TextField::TextChanged()
1605 Dali::Toolkit::TextField handle( GetOwner() );
1606 mTextChangedSignal.Emit( handle );
1609 void TextField::MaxLengthReached()
1611 Dali::Toolkit::TextField handle( GetOwner() );
1612 mMaxLengthReachedSignal.Emit( handle );
1615 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1617 Dali::Toolkit::TextField handle( GetOwner() );
1619 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1621 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1623 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1625 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1627 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1629 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1631 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1633 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1635 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1637 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1639 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1641 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1643 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1645 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1647 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1649 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1651 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1653 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1655 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1657 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1659 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1662 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1665 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1671 mClippingDecorationActors.push_back( actor );
1675 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1676 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1677 Self().Add( actor );
1678 mActiveLayer = actor;
1683 void TextField::OnSceneConnect( Dali::Actor actor )
1685 if ( mHasBeenStaged )
1687 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1691 mHasBeenStaged = true;
1695 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1697 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1698 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1701 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1706 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1711 void TextField::EnableClipping()
1715 // Creates an extra control to be used as stencil buffer.
1716 mStencil = Control::New();
1717 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1718 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1720 // Creates a background visual. Even if the color is transparent it updates the stencil.
1721 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1722 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1723 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1725 // Enable the clipping property.
1726 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1727 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1729 Self().Add( mStencil );
1733 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1735 mController->PasteClipboardItemEvent();
1738 void TextField::KeyboardStatusChanged(bool keyboardShown)
1740 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1742 // Just hide the grab handle when keyboard is hidden.
1743 if (!keyboardShown )
1745 mController->KeyboardFocusLostEvent();
1749 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1753 void TextField::OnSceneConnection( int depth )
1755 // Sets the depth to the visuals inside the text's decorator.
1756 mDecorator->SetTextDepth( depth );
1758 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1760 // Call the Control::OnSceneConnection() to set the depth of the background.
1761 Control::OnSceneConnection( depth );
1764 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1769 void TextField::OnIdleSignal()
1771 // Emits the change of input style signals.
1772 mController->ProcessInputStyleChangedSignals();
1774 // Set the pointer to null as the callback manager deletes the callback after execute it.
1775 mIdleCallback = NULL;
1778 TextField::TextField()
1779 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1780 mIdleCallback( NULL ),
1781 mAlignmentOffset( 0.f ),
1782 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1783 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1784 mHasBeenStaged( false )
1788 TextField::~TextField()
1790 UnparentAndReset( mStencil );
1792 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1794 Adaptor::Get().RemoveIdle( mIdleCallback );
1798 } // namespace Internal
1800 } // namespace Toolkit