2 * Copyright (c) 2019 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-editor-impl.h>
24 #include <dali/public-api/adaptor-framework/key.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/integration-api/adaptor-framework/adaptor.h>
34 #include <dali-toolkit/public-api/text/rendering-backend.h>
35 #include <dali-toolkit/public-api/text/text-enumerations.h>
36 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-devel.h>
38 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-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>
49 using namespace Dali::Toolkit::Text;
60 namespace // unnamed namespace
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
67 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
69 } // unnamed namespace
73 const char* const SCROLL_BAR_POSITION("sourcePosition");
74 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
75 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
76 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
81 return Toolkit::TextEditor::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text", STRING, TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "underline", MAP, UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "shadow", MAP, SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "emboss", MAP, EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "outline", MAP, OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize", FLOAT, PIXEL_SIZE )
133 DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
146 DALI_TYPE_REGISTRATION_END()
150 Toolkit::TextEditor TextEditor::New()
152 // Create the implementation, temporarily owned by this handle on stack
153 IntrusivePtr< TextEditor > impl = new TextEditor();
155 // Pass ownership to CustomActor handle
156 Toolkit::TextEditor handle( *impl );
158 // Second-phase init of the implementation
159 // This can only be done after the CustomActor connection has been made...
165 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
167 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
169 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
174 TextEditor& impl( GetImpl( textEditor ) );
178 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
180 int backend = value.Get< int >();
181 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
183 if( impl.mRenderingBackend != backend )
185 impl.mRenderingBackend = backend;
186 impl.mRenderer.Reset();
187 impl.RequestTextRelayout();
191 case Toolkit::TextEditor::Property::TEXT:
193 if( impl.mController )
195 const std::string& text = value.Get< std::string >();
196 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
198 impl.mController->SetText( text );
202 case Toolkit::TextEditor::Property::TEXT_COLOR:
204 if( impl.mController )
206 const Vector4& textColor = value.Get< Vector4 >();
207 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
209 if( impl.mController->GetDefaultColor() != textColor )
211 impl.mController->SetDefaultColor( textColor );
212 impl.mController->SetInputColor( textColor );
213 impl.mRenderer.Reset();
218 case Toolkit::TextEditor::Property::FONT_FAMILY:
220 if( impl.mController )
222 const std::string& fontFamily = value.Get< std::string >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
224 impl.mController->SetDefaultFontFamily( fontFamily );
228 case Toolkit::TextEditor::Property::FONT_STYLE:
230 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
233 case Toolkit::TextEditor::Property::POINT_SIZE:
235 if( impl.mController )
237 const float pointSize = value.Get< float >();
238 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
240 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
242 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
247 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
249 if( impl.mController )
251 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
252 if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) )
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
255 impl.mController->SetHorizontalAlignment( alignment );
260 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
262 const float threshold = value.Get< float >();
263 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
265 if( impl.mDecorator )
267 impl.mDecorator->SetScrollThreshold( threshold );
271 case Toolkit::TextEditor::Property::SCROLL_SPEED:
273 const float speed = value.Get< float >();
274 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
276 if( impl.mDecorator )
278 impl.mDecorator->SetScrollSpeed( speed );
282 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
284 if( impl.mDecorator )
286 const Vector4& color = value.Get< Vector4 >();
287 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
289 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
290 impl.RequestTextRelayout();
294 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
296 if( impl.mDecorator )
298 const Vector4& color = value.Get< Vector4 >();
299 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
301 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
302 impl.RequestTextRelayout();
306 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
308 if( impl.mController )
310 const bool enable = value.Get< bool >();
311 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
313 impl.mController->SetEnableCursorBlink( enable );
314 impl.RequestTextRelayout();
318 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
320 if( impl.mDecorator )
322 const float interval = value.Get< float >();
323 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
325 impl.mDecorator->SetCursorBlinkInterval( interval );
329 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
331 if( impl.mDecorator )
333 const float duration = value.Get< float >();
334 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
336 impl.mDecorator->SetCursorBlinkDuration( duration );
340 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
342 if( impl.mDecorator )
344 const int width = value.Get< int >();
345 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
347 impl.mDecorator->SetCursorWidth( width );
348 impl.mController->GetLayoutEngine().SetCursorWidth( width );
352 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
354 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
357 if( impl.mDecorator )
359 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
360 impl.RequestTextRelayout();
364 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
366 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
367 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
369 if( impl.mDecorator )
371 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
372 impl.RequestTextRelayout();
376 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
378 const Image image = Scripting::NewImage( value );
380 if( impl.mDecorator && image )
382 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
383 impl.RequestTextRelayout();
387 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
389 const Image image = Scripting::NewImage( value );
391 if( impl.mDecorator && image )
393 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
394 impl.RequestTextRelayout();
398 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
400 const Image image = Scripting::NewImage( value );
402 if( impl.mDecorator && image )
404 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
405 impl.RequestTextRelayout();
409 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
411 const Image image = Scripting::NewImage( value );
413 if( impl.mDecorator && image )
415 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
416 impl.RequestTextRelayout();
420 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
422 const Image image = Scripting::NewImage( value );
424 if( impl.mDecorator && image )
426 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
427 impl.RequestTextRelayout();
431 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
433 const Image image = Scripting::NewImage( value );
435 if( impl.mDecorator && image )
437 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
438 impl.RequestTextRelayout();
442 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
444 const Vector4 color = value.Get< Vector4 >();
445 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
447 if( impl.mDecorator )
449 impl.mDecorator->SetHighlightColor( color );
450 impl.RequestTextRelayout();
454 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
456 if( impl.mDecorator )
458 const Rect<int>& box = value.Get< Rect<int> >();
459 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
461 impl.mDecorator->SetBoundingBox( box );
462 impl.RequestTextRelayout();
466 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
468 if( impl.mController )
470 const bool enableMarkup = value.Get<bool>();
471 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
473 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
477 case Toolkit::TextEditor::Property::INPUT_COLOR:
479 if( impl.mController )
481 const Vector4& inputColor = value.Get< Vector4 >();
482 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
484 impl.mController->SetInputColor( inputColor );
488 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
490 if( impl.mController )
492 const std::string& fontFamily = value.Get< std::string >();
493 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
494 impl.mController->SetInputFontFamily( fontFamily );
498 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
500 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
503 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
505 if( impl.mController )
507 const float pointSize = value.Get< float >();
508 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
509 impl.mController->SetInputFontPointSize( pointSize );
513 case Toolkit::TextEditor::Property::LINE_SPACING:
515 if( impl.mController )
518 // The line spacing isn't supported by the TextEditor. Since it's supported
519 // by the TextLabel for now it must be ignored. The property is being shadowed
520 // locally so its value isn't affected.
521 const float lineSpacing = value.Get<float>();
522 impl.mLineSpacing = lineSpacing;
523 // set it to 0.0 due to missing implementation
524 impl.mController->SetDefaultLineSpacing( 0.0f );
525 impl.mRenderer.Reset();
529 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
531 if( impl.mController )
533 const float lineSpacing = value.Get<float>();
534 impl.mController->SetInputLineSpacing( lineSpacing );
535 impl.mRenderer.Reset();
539 case Toolkit::TextEditor::Property::UNDERLINE:
541 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
544 impl.mRenderer.Reset();
548 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
550 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
553 impl.mRenderer.Reset();
557 case Toolkit::TextEditor::Property::SHADOW:
559 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
562 impl.mRenderer.Reset();
566 case Toolkit::TextEditor::Property::INPUT_SHADOW:
568 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
571 impl.mRenderer.Reset();
575 case Toolkit::TextEditor::Property::EMBOSS:
577 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
580 impl.mRenderer.Reset();
584 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
586 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
589 impl.mRenderer.Reset();
593 case Toolkit::TextEditor::Property::OUTLINE:
595 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
598 impl.mRenderer.Reset();
602 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
604 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
607 impl.mRenderer.Reset();
611 case Toolkit::TextEditor::Property::SMOOTH_SCROLL:
613 const bool enable = value.Get< bool >();
614 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SMOOTH_SCROLL %d\n", enable );
616 impl.mScrollAnimationEnabled = enable;
619 case Toolkit::TextEditor::Property::SMOOTH_SCROLL_DURATION:
621 const float duration = value.Get< float >();
622 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SMOOTH_SCROLL_DURATION %f\n", duration );
624 impl.mScrollAnimationDuration = duration;
625 if ( impl.mTextVerticalScroller )
627 impl.mTextVerticalScroller->SetDuration( duration );
631 case Toolkit::TextEditor::Property::ENABLE_SCROLL_BAR:
633 const bool enable = value.Get< bool >();
634 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SHOW_SCROLL_BAR %d\n", enable );
636 impl.mScrollBarEnabled = enable;
639 case Toolkit::TextEditor::Property::SCROLL_BAR_SHOW_DURATION:
641 const float duration = value.Get< float >();
642 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SCROLL_BAR_SHOW_DURATION %f\n", duration );
644 impl.mAnimationPeriod.delaySeconds = duration;
647 case Toolkit::TextEditor::Property::SCROLL_BAR_FADE_DURATION:
649 const float duration = value.Get< float >();
650 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SCROLL_BAR_FADE_DURATION %f\n", duration );
652 impl.mAnimationPeriod.durationSeconds = duration;
655 case Toolkit::TextEditor::Property::PIXEL_SIZE:
657 if( impl.mController )
659 const float pixelSize = value.Get< float >();
660 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
662 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
664 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
669 case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT:
671 if( impl.mController )
673 const std::string& text = value.Get< std::string >();
674 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnPropertySet %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
676 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
680 case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR:
682 if( impl.mController )
684 const Vector4& textColor = value.Get< Vector4 >();
685 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
687 if( impl.mController->GetPlaceholderTextColor() != textColor )
689 impl.mController->SetPlaceholderTextColor( textColor );
690 impl.mRenderer.Reset();
695 case Toolkit::TextEditor::Property::ENABLE_SELECTION:
697 if( impl.mController )
699 const bool enableSelection = value.Get< bool >();
700 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
701 impl.mController->SetSelectionEnabled( enableSelection );
705 case Toolkit::TextEditor::Property::PLACEHOLDER:
707 const Property::Map* map = value.GetMap();
710 impl.mController->SetPlaceholderProperty( *map );
714 case Toolkit::TextEditor::Property::LINE_WRAP_MODE:
716 if( impl.mController )
718 Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
719 if( GetLineWrapModeEnumeration( value, lineWrapMode ) )
721 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode );
722 impl.mController->SetLineWrapMode( lineWrapMode );
727 case Toolkit::DevelTextEditor::Property::ENABLE_SHIFT_SELECTION:
729 if( impl.mController )
731 const bool shiftSelection = value.Get<bool>();
732 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
734 impl.mController->SetShiftSelectionEnabled( shiftSelection );
738 case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE:
740 if( impl.mController )
742 const bool grabHandleEnabled = value.Get<bool>();
743 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
745 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
749 case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
751 if( impl.mController )
753 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
761 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
763 Property::Value value;
765 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
769 TextEditor& impl( GetImpl( textEditor ) );
773 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
775 value = impl.mRenderingBackend;
778 case Toolkit::TextEditor::Property::TEXT:
780 if( impl.mController )
783 impl.mController->GetText( text );
784 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
789 case Toolkit::TextEditor::Property::TEXT_COLOR:
791 if ( impl.mController )
793 value = impl.mController->GetDefaultColor();
797 case Toolkit::TextEditor::Property::FONT_FAMILY:
799 if( impl.mController )
801 value = impl.mController->GetDefaultFontFamily();
805 case Toolkit::TextEditor::Property::FONT_STYLE:
807 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
810 case Toolkit::TextEditor::Property::POINT_SIZE:
812 if( impl.mController )
814 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
818 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
820 if( impl.mController )
822 const char* name = GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
825 value = std::string( name );
830 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
832 if( impl.mDecorator )
834 value = impl.mDecorator->GetScrollThreshold();
838 case Toolkit::TextEditor::Property::SCROLL_SPEED:
840 if( impl.mDecorator )
842 value = impl.mDecorator->GetScrollSpeed();
846 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
848 if( impl.mDecorator )
850 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
854 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
856 if( impl.mDecorator )
858 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
862 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
864 value = impl.mController->GetEnableCursorBlink();
867 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
869 if( impl.mDecorator )
871 value = impl.mDecorator->GetCursorBlinkInterval();
875 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
877 if( impl.mDecorator )
879 value = impl.mDecorator->GetCursorBlinkDuration();
883 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
885 if( impl.mDecorator )
887 value = impl.mDecorator->GetCursorWidth();
891 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
893 if( impl.mDecorator )
895 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
898 value = image.GetUrl();
903 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
905 if( impl.mDecorator )
907 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
910 value = image.GetUrl();
915 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
917 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
920 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
922 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
925 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
927 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
930 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
932 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
935 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
937 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
940 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
942 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
945 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
947 if( impl.mDecorator )
949 value = impl.mDecorator->GetHighlightColor();
953 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
955 if( impl.mDecorator )
957 Rect<int> boundingBox;
958 impl.mDecorator->GetBoundingBox( boundingBox );
963 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
965 if( impl.mController )
967 value = impl.mController->IsMarkupProcessorEnabled();
971 case Toolkit::TextEditor::Property::INPUT_COLOR:
973 if( impl.mController )
975 value = impl.mController->GetInputColor();
979 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
981 if( impl.mController )
983 value = impl.mController->GetInputFontFamily();
987 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
989 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
992 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
994 if( impl.mController )
996 value = impl.mController->GetInputFontPointSize();
1000 case Toolkit::TextEditor::Property::LINE_SPACING:
1002 if( impl.mController )
1004 // LINE_SPACING isn't implemented for the TextEditor. Returning
1005 // only shadowed value, not the real one.
1006 value = impl.mLineSpacing;
1010 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
1012 if( impl.mController )
1014 value = impl.mController->GetInputLineSpacing();
1018 case Toolkit::TextEditor::Property::UNDERLINE:
1020 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1023 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
1025 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1028 case Toolkit::TextEditor::Property::SHADOW:
1030 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1033 case Toolkit::TextEditor::Property::INPUT_SHADOW:
1035 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1038 case Toolkit::TextEditor::Property::EMBOSS:
1040 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1043 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
1045 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1048 case Toolkit::TextEditor::Property::OUTLINE:
1050 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1053 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
1055 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1058 case Toolkit::TextEditor::Property::SMOOTH_SCROLL:
1060 value = impl.mScrollAnimationEnabled;
1063 case Toolkit::TextEditor::Property::SMOOTH_SCROLL_DURATION:
1065 value = impl.mScrollAnimationDuration;
1068 case Toolkit::TextEditor::Property::ENABLE_SCROLL_BAR:
1070 value = impl.mScrollBarEnabled;
1073 case Toolkit::TextEditor::Property::SCROLL_BAR_SHOW_DURATION:
1075 value = impl.mAnimationPeriod.delaySeconds;
1078 case Toolkit::TextEditor::Property::SCROLL_BAR_FADE_DURATION:
1080 value = impl.mAnimationPeriod.durationSeconds;
1083 case Toolkit::TextEditor::Property::PIXEL_SIZE:
1085 if( impl.mController )
1087 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1091 case Toolkit::TextEditor::Property::LINE_COUNT:
1093 if( impl.mController )
1095 float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
1096 value = impl.mController->GetLineCount( width );
1100 case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT:
1102 if( impl.mController )
1105 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
1110 case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR:
1112 if( impl.mController )
1114 value = impl.mController->GetPlaceholderTextColor();
1118 case Toolkit::TextEditor::Property::ENABLE_SELECTION:
1120 if( impl.mController )
1122 value = impl.mController->IsSelectionEnabled();
1126 case Toolkit::TextEditor::Property::PLACEHOLDER:
1129 impl.mController->GetPlaceholderProperty( map );
1133 case Toolkit::TextEditor::Property::LINE_WRAP_MODE:
1135 if( impl.mController )
1137 value = impl.mController->GetLineWrapMode();
1141 case Toolkit::DevelTextEditor::Property::ENABLE_SHIFT_SELECTION:
1143 if( impl.mController )
1145 value = impl.mController->IsShiftSelectionEnabled();
1149 case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE:
1151 if( impl.mController )
1153 value = impl.mController->IsGrabHandleEnabled();
1157 case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1159 if( impl.mController )
1161 value = impl.mController->IsMatchSystemLanguageDirection();
1171 InputMethodContext TextEditor::GetInputMethodContext()
1173 return mInputMethodContext;
1176 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1178 Dali::BaseHandle handle( object );
1180 bool connected( true );
1181 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
1183 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1185 editor.TextChangedSignal().Connect( tracker, functor );
1187 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1189 editor.InputStyleChangedSignal().Connect( tracker, functor );
1193 // signalName does not match any signal
1200 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
1202 return mTextChangedSignal;
1205 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
1207 return mInputStyleChangedSignal;
1210 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
1212 return mScrollStateChangedSignal;
1215 void TextEditor::OnInitialize()
1217 Actor self = Self();
1219 mController = Text::Controller::New( this, this );
1221 mDecorator = Text::Decorator::New( *mController,
1224 mInputMethodContext = InputMethodContext::New( self );
1226 mController->GetLayoutEngine().SetLayout( Layout::Engine::MULTI_LINE_BOX );
1228 // Enables the text input.
1229 mController->EnableTextInput( mDecorator, mInputMethodContext );
1231 // Enables the vertical scrolling after the text input has been enabled.
1232 mController->SetVerticalScrollEnabled( true );
1234 // Disables the horizontal scrolling.
1235 mController->SetHorizontalScrollEnabled( false );
1237 // Sets the maximum number of characters.
1238 mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
1240 // Enable the smooth handle panning.
1241 mController->SetSmoothHandlePanEnabled( true );
1243 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1244 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1246 // Sets layoutDirection value
1247 Dali::Stage stage = Dali::Stage::GetCurrent();
1248 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1249 mController->SetLayoutDirection( layoutDirection );
1251 // Forward input events to controller
1252 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1253 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1255 self.TouchSignal().Connect( this, &TextEditor::OnTouched );
1257 // Set BoundingBox to stage size if not already set.
1258 Rect<int> boundingBox;
1259 mDecorator->GetBoundingBox( boundingBox );
1261 if( boundingBox.IsEmpty() )
1263 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1264 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1267 // Whether to flip the selection handles as soon as they cross.
1268 mDecorator->FlipSelectionHandlesOnCrossEnabled( true );
1270 // Set the default scroll speed.
1271 mDecorator->SetScrollSpeed( DEFAULT_SCROLL_SPEED );
1273 // Fill-parent area by default
1274 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1275 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1276 self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
1278 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1280 // Creates an extra control to be used as stencil buffer.
1281 mStencil = Control::New();
1282 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1283 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1285 // Creates a background visual. Even if the color is transparent it updates the stencil.
1286 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1287 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1288 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1290 // Enable the clipping property.
1291 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1292 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1294 self.Add( mStencil );
1297 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1299 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
1303 case StyleChange::DEFAULT_FONT_CHANGE:
1305 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
1306 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1307 // Property system did not set the font so should update it.
1308 mController->UpdateAfterFontChange( newFont );
1313 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1315 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1319 case StyleChange::THEME_CHANGE:
1321 // Nothing to do, let control base class handle this
1326 // Up call to Control
1327 Control::OnStyleChange( styleManager, change );
1330 Vector3 TextEditor::GetNaturalSize()
1333 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1335 Vector3 naturalSize = mController->GetNaturalSize();
1336 naturalSize.width += ( padding.start + padding.end );
1337 naturalSize.height += ( padding.top + padding.bottom );
1342 float TextEditor::GetHeightForWidth( float width )
1345 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1346 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1349 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
1351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
1353 Actor self = Self();
1356 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1358 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1360 // Support Right-To-Left of padding
1361 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1362 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1364 std::swap( padding.start, padding.end );
1369 mStencil.SetPosition( padding.start, padding.top );
1373 mActiveLayer.SetPosition( padding.start, padding.top );
1376 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1378 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
1384 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1386 mDecorator->Relayout( size );
1391 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1394 RenderText( updateTextType );
1398 // The text-editor emits signals when the input style changes. These changes of style are
1399 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1400 // can't be emitted during the size negotiation as the callbacks may update the UI.
1401 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1402 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1404 if( Adaptor::IsAvailable() )
1406 Adaptor& adaptor = Adaptor::Get();
1408 if( NULL == mIdleCallback )
1410 // @note: The callback manager takes the ownership of the callback object.
1411 mIdleCallback = MakeCallback( this, &TextEditor::OnIdleSignal );
1412 adaptor.AddIdle( mIdleCallback, false );
1418 void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
1420 Actor renderableActor;
1422 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1426 Dali::Toolkit::TextEditor handle = Dali::Toolkit::TextEditor( GetOwner() );
1428 renderableActor = mRenderer->Render( mController->GetView(),
1430 Property::INVALID_INDEX, // Animatable property not supported
1432 DepthIndex::CONTENT );
1435 if( renderableActor != mRenderableActor )
1437 UnparentAndReset( mRenderableActor );
1438 mRenderableActor = renderableActor;
1442 if( mRenderableActor )
1444 // Make sure the actors are parented correctly with/without clipping
1445 Actor self = mStencil ? mStencil : Self();
1447 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1448 endIt = mClippingDecorationActors.end();
1453 it->LowerToBottom();
1455 mClippingDecorationActors.clear();
1457 self.Add( mRenderableActor );
1459 ApplyScrollPosition();
1464 void TextEditor::OnKeyInputFocusGained()
1466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
1467 if ( mInputMethodContext )
1469 mInputMethodContext.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
1471 mInputMethodContext.EventReceivedSignal().Connect( this, &TextEditor::OnInputMethodContextEvent );
1473 // Notify that the text editing start.
1474 mInputMethodContext.Activate();
1476 // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
1477 mInputMethodContext.SetRestoreAfterFocusLost( true );
1479 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1483 notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
1486 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1488 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1491 void TextEditor::OnKeyInputFocusLost()
1493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
1494 if ( mInputMethodContext )
1496 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
1498 // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
1499 mInputMethodContext.SetRestoreAfterFocusLost( false );
1501 // Notify that the text editing finish.
1502 mInputMethodContext.Deactivate();
1504 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextEditor::OnInputMethodContextEvent );
1506 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1510 notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
1513 mController->KeyboardFocusLostEvent();
1515 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1518 void TextEditor::OnTap( const TapGesture& gesture )
1520 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
1521 if ( mInputMethodContext )
1523 mInputMethodContext.Activate();
1525 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1527 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1528 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1533 void TextEditor::OnPan( const PanGesture& gesture )
1535 mController->PanEvent( gesture.state, gesture.displacement );
1538 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1540 if ( mInputMethodContext )
1542 mInputMethodContext.Activate();
1545 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1546 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1551 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1553 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1555 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1557 // Make sure ClearKeyInputFocus when only key is up
1558 if( event.state == KeyEvent::Up )
1560 ClearKeyInputFocus();
1566 return mController->KeyEvent( event );
1569 void TextEditor::RequestTextRelayout()
1574 void TextEditor::TextChanged()
1576 Dali::Toolkit::TextEditor handle( GetOwner() );
1577 mTextChangedSignal.Emit( handle );
1580 void TextEditor::MaxLengthReached()
1582 // Nothing to do as TextEditor doesn't emit a max length reached signal.
1585 void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1587 Dali::Toolkit::TextEditor handle( GetOwner() );
1589 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
1591 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1593 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR );
1595 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1597 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY );
1599 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1601 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE );
1603 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1605 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1607 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1609 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1611 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1613 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1615 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_LINE_SPACING ) )
1617 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING );
1619 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1621 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE );
1623 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1625 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW );
1627 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1629 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS );
1631 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1633 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE );
1636 mInputStyleChangedSignal.Emit( handle, editorInputStyleMask );
1639 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1645 mClippingDecorationActors.push_back( actor );
1649 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1650 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1651 Self().Add( actor );
1652 mActiveLayer = actor;
1657 void TextEditor::UpdateScrollBar()
1659 using namespace Dali;
1661 float scrollPosition;
1664 bool latestScrolled;
1666 if ( !mScrollBarEnabled )
1670 latestScrolled = mController->GetTextScrollInfo( scrollPosition, controlSize, layoutSize );
1671 if ( !latestScrolled || controlSize > layoutSize)
1676 CustomActor self = Self();
1679 mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::Vertical );
1680 mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::Variable );
1681 mScrollBar.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
1682 mScrollBar.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
1683 mScrollBar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1684 mScrollBar.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
1686 // Register the scroll position property
1687 Property::Index propertyScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION, scrollPosition );
1688 // Register the minimum scroll position property
1689 Property::Index propertyMinScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MIN, 0.0f );
1690 // Register the maximum scroll position property
1691 Property::Index propertyMaxScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize) );
1692 // Register the scroll content size property
1693 Property::Index propertyScrollContentSize = self.RegisterProperty( SCROLL_BAR_CONTENT_SIZE, layoutSize );
1695 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1697 // Set style name of ScrollBar for styling
1698 mScrollBar.SetStyleName("TextEditorScrollBar");
1699 Toolkit::Control scrollIndicator = Toolkit::Control::DownCast( mScrollBar.GetScrollIndicator() );
1700 if( scrollIndicator )
1702 // Set style name of ScrollBarIndicator for styling
1703 scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1706 self.Add( mScrollBar );
1710 Property::Index propertyScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION );
1711 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION_MAX );
1712 Property::Index propertyScrollContentSize = self.GetPropertyIndex( SCROLL_BAR_CONTENT_SIZE );
1714 self.SetProperty( propertyScrollPosition, scrollPosition );
1715 self.SetProperty( propertyMaxScrollPosition, (layoutSize - controlSize) );
1716 self.SetProperty( propertyScrollContentSize, layoutSize );
1719 // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1720 if( !mScrollStarted )
1722 mScrollStarted = true;
1723 Dali::Toolkit::TextEditor handle( GetOwner() );
1724 mScrollStateChangedSignal.Emit( handle, Toolkit::TextEditor::Scroll::STARTED );
1727 Actor indicator = mScrollBar.GetScrollIndicator();
1730 mAnimation.Stop(); // Cancel any animation
1734 mAnimation = Animation::New( mAnimationPeriod.durationSeconds );
1736 indicator.SetProperty( DevelActor::Property::OPACITY,1.0f);
1737 mAnimation.AnimateTo( Property( indicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod );
1739 mAnimation.FinishedSignal().Connect( this, &TextEditor::OnScrollIndicatorAnimationFinished );
1742 void TextEditor::OnScrollIndicatorAnimationFinished( Animation& animation )
1744 // If animation is successfully ended, then emit ScrollStateChangedSignal
1745 if( animation.GetCurrentProgress() == 0.0f )
1747 mScrollStarted = false;
1748 Dali::Toolkit::TextEditor handle( GetOwner() );
1749 mScrollStateChangedSignal.Emit( handle, Toolkit::TextEditor::Scroll::FINISHED );
1753 void TextEditor::OnStageConnect( Dali::Actor actor )
1755 if ( mHasBeenStaged )
1757 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1761 mHasBeenStaged = true;
1765 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1767 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1768 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1771 void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1775 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1780 Scripting::CreatePropertyMap( image, map );
1786 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1788 mController->PasteClipboardItemEvent();
1791 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1793 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1795 // Just hide the grab handle when keyboard is hidden.
1796 if (!keyboardShown )
1798 mController->KeyboardFocusLostEvent();
1802 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1806 void TextEditor::OnStageConnection( int depth )
1808 // Sets the depth to the visuals inside the text's decorator.
1809 mDecorator->SetTextDepth( depth );
1811 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1813 // Call the Control::OnStageConnection() to set the depth of the background.
1814 Control::OnStageConnection( depth );
1817 bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
1822 void TextEditor::OnIdleSignal()
1824 // Emits the change of input style signals.
1825 mController->ProcessInputStyleChangedSignals();
1827 // Set the pointer to null as the callback manager deletes the callback after execute it.
1828 mIdleCallback = NULL;
1831 void TextEditor::ApplyScrollPosition()
1833 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1834 float scrollAmount = 0.0f;
1836 if ( mScrollAnimationEnabled )
1838 scrollAmount = mController->GetScrollAmountByUserInput();
1840 if ( mTextVerticalScroller )
1842 mTextVerticalScroller->CheckStartAnimation( mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount );
1844 else if ( Equals( scrollAmount, 0.0f, Math::MACHINE_EPSILON_1 ))
1846 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount );
1850 mTextVerticalScroller = Text::TextVerticalScroller::New();
1851 if ( !Equals( mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1 ))
1853 mTextVerticalScroller->SetDuration( mScrollAnimationDuration );
1855 mTextVerticalScroller->CheckStartAnimation( mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount );
1859 TextEditor::TextEditor()
1860 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1861 mAnimationPeriod( 0.0f, 0.0f ),
1862 mIdleCallback( NULL ),
1863 mAlignmentOffset( 0.f ),
1864 mScrollAnimationDuration( 0.f ),
1865 mLineSpacing( 0.f ),
1866 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1867 mHasBeenStaged( false ),
1868 mScrollAnimationEnabled( false ),
1869 mScrollBarEnabled( false ),
1870 mScrollStarted( false )
1874 TextEditor::~TextEditor()
1876 UnparentAndReset( mStencil );
1878 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1880 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1881 Adaptor::Get().RemoveIdle( mIdleCallback );
1885 } // namespace Internal
1887 } // namespace Toolkit