2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-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/object/property-helper-devel.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptors/adaptor.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
37 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
38 #include <dali-toolkit/internal/text/rendering/text-backend.h>
39 #include <dali-toolkit/internal/text/text-effects-style.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
41 #include <dali-toolkit/internal/text/text-view.h>
42 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 using namespace Dali::Toolkit::Text;
55 namespace // unnamed namespace
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
62 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
63 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
64 } // unnamed namespace
69 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
71 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
72 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
73 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
75 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
77 const char* const SCROLL_BAR_POSITION("sourcePosition");
78 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
79 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
80 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
85 return Toolkit::TextEditor::New();
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text", STRING, TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle", MAP, FONT_STYLE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle", MAP, INPUT_FONT_STYLE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "underline", MAP, UNDERLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputUnderline", MAP, INPUT_UNDERLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "shadow", MAP, SHADOW )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputShadow", MAP, INPUT_SHADOW )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "emboss", MAP, EMBOSS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputEmboss", MAP, INPUT_EMBOSS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "outline", MAP, OUTLINE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputOutline", MAP, INPUT_OUTLINE )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "smoothScroll", BOOLEAN, SMOOTH_SCROLL )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "smoothScrollDuration", FLOAT, SMOOTH_SCROLL_DURATION )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableScrollBar", BOOLEAN, ENABLE_SCROLL_BAR )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration", FLOAT, SCROLL_BAR_SHOW_DURATION )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration", FLOAT, SCROLL_BAR_FADE_DURATION )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
138 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
140 DALI_TYPE_REGISTRATION_END()
144 Toolkit::TextEditor TextEditor::New()
146 // Create the implementation, temporarily owned by this handle on stack
147 IntrusivePtr< TextEditor > impl = new TextEditor();
149 // Pass ownership to CustomActor handle
150 Toolkit::TextEditor handle( *impl );
152 // Second-phase init of the implementation
153 // This can only be done after the CustomActor connection has been made...
159 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
161 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
163 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
168 TextEditor& impl( GetImpl( textEditor ) );
172 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
174 int backend = value.Get< int >();
175 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
177 if( impl.mRenderingBackend != backend )
179 impl.mRenderingBackend = backend;
180 impl.mRenderer.Reset();
181 impl.RequestTextRelayout();
185 case Toolkit::TextEditor::Property::TEXT:
187 if( impl.mController )
189 const std::string& text = value.Get< std::string >();
190 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
192 impl.mController->SetText( text );
196 case Toolkit::TextEditor::Property::TEXT_COLOR:
198 if( impl.mController )
200 const Vector4& textColor = value.Get< Vector4 >();
201 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 );
203 if( impl.mController->GetDefaultColor() != textColor )
205 impl.mController->SetDefaultColor( textColor );
206 impl.mController->SetInputColor( textColor );
207 impl.mRenderer.Reset();
212 case Toolkit::TextEditor::Property::FONT_FAMILY:
214 if( impl.mController )
216 const std::string& fontFamily = value.Get< std::string >();
217 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
218 impl.mController->SetDefaultFontFamily( fontFamily );
222 case Toolkit::TextEditor::Property::FONT_STYLE:
224 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
227 case Toolkit::TextEditor::Property::POINT_SIZE:
229 if( impl.mController )
231 const float pointSize = value.Get< float >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
234 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
236 impl.mController->SetDefaultPointSize( pointSize );
241 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
243 if( impl.mController )
245 const std::string& alignStr = value.Get< std::string >();
246 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
248 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
249 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
250 HORIZONTAL_ALIGNMENT_STRING_TABLE,
251 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
254 impl.mController->SetHorizontalAlignment( alignment );
259 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
261 const float threshold = value.Get< float >();
262 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
264 if( impl.mDecorator )
266 impl.mDecorator->SetScrollThreshold( threshold );
270 case Toolkit::TextEditor::Property::SCROLL_SPEED:
272 const float speed = value.Get< float >();
273 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
275 if( impl.mDecorator )
277 impl.mDecorator->SetScrollSpeed( speed );
281 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
283 if( impl.mDecorator )
285 const Vector4& color = value.Get< Vector4 >();
286 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 );
288 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
289 impl.RequestTextRelayout();
293 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
295 if( impl.mDecorator )
297 const Vector4& color = value.Get< Vector4 >();
298 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 );
300 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
301 impl.RequestTextRelayout();
305 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
307 if( impl.mController )
309 const bool enable = value.Get< bool >();
310 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
312 impl.mController->SetEnableCursorBlink( enable );
313 impl.RequestTextRelayout();
317 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
319 if( impl.mDecorator )
321 const float interval = value.Get< float >();
322 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
324 impl.mDecorator->SetCursorBlinkInterval( interval );
328 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
330 if( impl.mDecorator )
332 const float duration = value.Get< float >();
333 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
335 impl.mDecorator->SetCursorBlinkDuration( duration );
339 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
341 if( impl.mDecorator )
343 const int width = value.Get< int >();
344 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
346 impl.mDecorator->SetCursorWidth( width );
347 impl.mController->GetLayoutEngine().SetCursorWidth( width );
351 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
353 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
354 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
356 if( impl.mDecorator )
358 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
359 impl.RequestTextRelayout();
363 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
365 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
366 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
368 if( impl.mDecorator )
370 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
371 impl.RequestTextRelayout();
375 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
377 const Image image = Scripting::NewImage( value );
379 if( impl.mDecorator && image )
381 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
382 impl.RequestTextRelayout();
386 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
388 const Image image = Scripting::NewImage( value );
390 if( impl.mDecorator && image )
392 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
393 impl.RequestTextRelayout();
397 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
399 const Image image = Scripting::NewImage( value );
401 if( impl.mDecorator && image )
403 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
404 impl.RequestTextRelayout();
408 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
410 const Image image = Scripting::NewImage( value );
412 if( impl.mDecorator && image )
414 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
415 impl.RequestTextRelayout();
419 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
421 const Image image = Scripting::NewImage( value );
423 if( impl.mDecorator && image )
425 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
426 impl.RequestTextRelayout();
430 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
432 const Image image = Scripting::NewImage( value );
434 if( impl.mDecorator && image )
436 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
437 impl.RequestTextRelayout();
441 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
443 const Vector4 color = value.Get< Vector4 >();
444 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 );
446 if( impl.mDecorator )
448 impl.mDecorator->SetHighlightColor( color );
449 impl.RequestTextRelayout();
453 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
455 if( impl.mDecorator )
457 const Rect<int>& box = value.Get< Rect<int> >();
458 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 );
460 impl.mDecorator->SetBoundingBox( box );
461 impl.RequestTextRelayout();
465 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
467 if( impl.mController )
469 const bool enableMarkup = value.Get<bool>();
470 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
472 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
476 case Toolkit::TextEditor::Property::INPUT_COLOR:
478 if( impl.mController )
480 const Vector4& inputColor = value.Get< Vector4 >();
481 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 );
483 impl.mController->SetInputColor( inputColor );
487 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
489 if( impl.mController )
491 const std::string& fontFamily = value.Get< std::string >();
492 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
493 impl.mController->SetInputFontFamily( fontFamily );
497 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
499 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
502 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
504 if( impl.mController )
506 const float pointSize = value.Get< float >();
507 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
508 impl.mController->SetInputFontPointSize( pointSize );
512 case Toolkit::TextEditor::Property::LINE_SPACING:
514 if( impl.mController )
516 const float lineSpacing = value.Get<float>();
517 impl.mController->SetDefaultLineSpacing( lineSpacing );
518 impl.mRenderer.Reset();
522 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
524 if( impl.mController )
526 const float lineSpacing = value.Get<float>();
527 impl.mController->SetInputLineSpacing( lineSpacing );
528 impl.mRenderer.Reset();
532 case Toolkit::TextEditor::Property::UNDERLINE:
534 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
537 impl.mRenderer.Reset();
541 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
543 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
546 impl.mRenderer.Reset();
550 case Toolkit::TextEditor::Property::SHADOW:
552 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
555 impl.mRenderer.Reset();
559 case Toolkit::TextEditor::Property::INPUT_SHADOW:
561 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
564 impl.mRenderer.Reset();
568 case Toolkit::TextEditor::Property::EMBOSS:
570 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
573 impl.mRenderer.Reset();
577 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
579 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
582 impl.mRenderer.Reset();
586 case Toolkit::TextEditor::Property::OUTLINE:
588 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
591 impl.mRenderer.Reset();
595 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
597 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
600 impl.mRenderer.Reset();
604 case Toolkit::DevelTextEditor::Property::SMOOTH_SCROLL:
606 const bool enable = value.Get< bool >();
607 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SMOOTH_SCROLL %d\n", enable );
609 impl.mScrollAnimationEnabled = enable;
612 case Toolkit::DevelTextEditor::Property::SMOOTH_SCROLL_DURATION:
614 const float duration = value.Get< float >();
615 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SMOOTH_SCROLL_DURATION %f\n", duration );
617 impl.mScrollAnimationDuration = duration;
618 if ( impl.mTextVerticalScroller )
620 impl.mTextVerticalScroller->SetDuration( duration );
624 case Toolkit::DevelTextEditor::Property::ENABLE_SCROLL_BAR:
626 const bool enable = value.Get< bool >();
627 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SHOW_SCROLL_BAR %d\n", enable );
629 impl.mScrollBarEnabled = enable;
632 case Toolkit::DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION:
634 const float duration = value.Get< float >();
635 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SCROLL_BAR_SHOW_DURATION %f\n", duration );
637 impl.mAnimationPeriod.delaySeconds = duration;
640 case Toolkit::DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION:
642 const float duration = value.Get< float >();
643 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor SCROLL_BAR_FADE_DURATION %f\n", duration );
645 impl.mAnimationPeriod.durationSeconds = duration;
652 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
654 Property::Value value;
656 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
660 TextEditor& impl( GetImpl( textEditor ) );
664 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
666 value = impl.mRenderingBackend;
669 case Toolkit::TextEditor::Property::TEXT:
671 if( impl.mController )
674 impl.mController->GetText( text );
675 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
680 case Toolkit::TextEditor::Property::TEXT_COLOR:
682 if ( impl.mController )
684 value = impl.mController->GetDefaultColor();
688 case Toolkit::TextEditor::Property::FONT_FAMILY:
690 if( impl.mController )
692 value = impl.mController->GetDefaultFontFamily();
696 case Toolkit::TextEditor::Property::FONT_STYLE:
698 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
701 case Toolkit::TextEditor::Property::POINT_SIZE:
703 if( impl.mController )
705 value = impl.mController->GetDefaultPointSize();
709 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
711 if( impl.mController )
713 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
714 HORIZONTAL_ALIGNMENT_STRING_TABLE,
715 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
718 value = std::string( name );
723 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
725 if( impl.mDecorator )
727 value = impl.mDecorator->GetScrollThreshold();
731 case Toolkit::TextEditor::Property::SCROLL_SPEED:
733 if( impl.mDecorator )
735 value = impl.mDecorator->GetScrollSpeed();
739 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
741 if( impl.mDecorator )
743 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
747 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
749 if( impl.mDecorator )
751 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
755 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
757 value = impl.mController->GetEnableCursorBlink();
760 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
762 if( impl.mDecorator )
764 value = impl.mDecorator->GetCursorBlinkInterval();
768 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
770 if( impl.mDecorator )
772 value = impl.mDecorator->GetCursorBlinkDuration();
776 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
778 if( impl.mDecorator )
780 value = impl.mDecorator->GetCursorWidth();
784 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
786 if( impl.mDecorator )
788 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
791 value = image.GetUrl();
796 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
798 if( impl.mDecorator )
800 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
803 value = image.GetUrl();
808 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
810 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
813 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
815 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
818 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
820 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
823 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
825 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
828 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
830 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
833 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
835 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
838 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
840 if( impl.mDecorator )
842 value = impl.mDecorator->GetHighlightColor();
846 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
848 if( impl.mDecorator )
850 Rect<int> boundingBox;
851 impl.mDecorator->GetBoundingBox( boundingBox );
856 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
858 if( impl.mController )
860 value = impl.mController->IsMarkupProcessorEnabled();
864 case Toolkit::TextEditor::Property::INPUT_COLOR:
866 if( impl.mController )
868 value = impl.mController->GetInputColor();
872 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
874 if( impl.mController )
876 value = impl.mController->GetInputFontFamily();
880 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
882 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
885 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
887 if( impl.mController )
889 value = impl.mController->GetInputFontPointSize();
893 case Toolkit::TextEditor::Property::LINE_SPACING:
895 if( impl.mController )
897 value = impl.mController->GetDefaultLineSpacing();
901 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
903 if( impl.mController )
905 value = impl.mController->GetInputLineSpacing();
909 case Toolkit::TextEditor::Property::UNDERLINE:
911 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
914 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
916 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
919 case Toolkit::TextEditor::Property::SHADOW:
921 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
924 case Toolkit::TextEditor::Property::INPUT_SHADOW:
926 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
929 case Toolkit::TextEditor::Property::EMBOSS:
931 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
934 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
936 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
939 case Toolkit::TextEditor::Property::OUTLINE:
941 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
944 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
946 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
949 case Toolkit::DevelTextEditor::Property::SMOOTH_SCROLL:
951 value = impl.mScrollAnimationEnabled;
954 case Toolkit::DevelTextEditor::Property::SMOOTH_SCROLL_DURATION:
956 value = impl.mScrollAnimationDuration;
959 case Toolkit::DevelTextEditor::Property::ENABLE_SCROLL_BAR:
961 value = impl.mScrollBarEnabled;
964 case Toolkit::DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION:
966 value = impl.mAnimationPeriod.delaySeconds;
969 case Toolkit::DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION:
971 value = impl.mAnimationPeriod.durationSeconds;
980 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
982 Dali::BaseHandle handle( object );
984 bool connected( true );
985 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
987 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
989 editor.TextChangedSignal().Connect( tracker, functor );
991 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
993 editor.InputStyleChangedSignal().Connect( tracker, functor );
997 // signalName does not match any signal
1004 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
1006 return mTextChangedSignal;
1009 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
1011 return mInputStyleChangedSignal;
1014 void TextEditor::OnInitialize()
1016 Actor self = Self();
1018 mController = Text::Controller::New( this, this );
1020 mDecorator = Text::Decorator::New( *mController,
1023 mController->GetLayoutEngine().SetLayout( Layout::Engine::MULTI_LINE_BOX );
1025 // Enables the text input.
1026 mController->EnableTextInput( mDecorator );
1028 // Enables the vertical scrolling after the text input has been enabled.
1029 mController->SetVerticalScrollEnabled( true );
1031 // Disables the horizontal scrolling.
1032 mController->SetHorizontalScrollEnabled( false );
1034 // Sets the maximum number of characters.
1035 mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
1037 // Enable the smooth handle panning.
1038 mController->SetSmoothHandlePanEnabled( true );
1040 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1041 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1043 // Forward input events to controller
1044 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1045 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1047 mImfManager = ImfManager::Get();
1049 self.TouchSignal().Connect( this, &TextEditor::OnTouched );
1051 // Set BoundingBox to stage size if not already set.
1052 Rect<int> boundingBox;
1053 mDecorator->GetBoundingBox( boundingBox );
1055 if( boundingBox.IsEmpty() )
1057 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1058 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1061 // Whether to flip the selection handles as soon as they cross.
1062 mDecorator->FlipSelectionHandlesOnCrossEnabled( true );
1064 // Set the default scroll speed.
1065 mDecorator->SetScrollSpeed( DEFAULT_SCROLL_SPEED );
1067 // Fill-parent area by default
1068 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1069 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1070 self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
1072 // Creates an extra control to be used as stencil buffer.
1073 mStencil = Control::New();
1074 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1075 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1077 // Creates a background visual. Even if the color is transparent it updates the stencil.
1078 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1079 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1080 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1082 // Enable the clipping property.
1083 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1084 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1086 self.Add( mStencil );
1089 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1091 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
1095 case StyleChange::DEFAULT_FONT_CHANGE:
1097 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
1098 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1099 // Property system did not set the font so should update it.
1100 mController->UpdateAfterFontChange( newFont );
1105 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1107 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1111 case StyleChange::THEME_CHANGE:
1113 // Nothing to do, let control base class handle this
1118 // Up call to Control
1119 Control::OnStyleChange( styleManager, change );
1122 Vector3 TextEditor::GetNaturalSize()
1124 return mController->GetNaturalSize();
1127 float TextEditor::GetHeightForWidth( float width )
1129 return mController->GetHeightForWidth( width );
1132 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
1134 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
1136 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1138 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1141 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
1144 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1146 mDecorator->Relayout( size );
1151 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1154 RenderText( updateTextType );
1157 // The text-editor emits signals when the input style changes. These changes of style are
1158 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1159 // can't be emitted during the size negotiation as the callbacks may update the UI.
1160 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1161 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1163 if( Adaptor::IsAvailable() )
1165 Adaptor& adaptor = Adaptor::Get();
1167 if( NULL == mIdleCallback )
1169 // @note: The callback manager takes the ownership of the callback object.
1170 mIdleCallback = MakeCallback( this, &TextEditor::OnIdleSignal );
1171 adaptor.AddIdle( mIdleCallback );
1177 void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
1179 Actor renderableActor;
1181 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1185 renderableActor = mRenderer->Render( mController->GetView(),
1187 DepthIndex::CONTENT );
1190 if( renderableActor != mRenderableActor )
1192 UnparentAndReset( mRenderableActor );
1193 mRenderableActor = renderableActor;
1197 if( mRenderableActor )
1199 // Make sure the actors are parented correctly with/without clipping
1200 Actor self = mStencil ? mStencil : Self();
1202 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1203 endIt = mClippingDecorationActors.end();
1209 mClippingDecorationActors.clear();
1211 self.Add( mRenderableActor );
1213 ApplyScrollPosition();
1218 void TextEditor::OnKeyInputFocusGained()
1220 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
1222 mImfManager.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
1224 mImfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
1226 // Notify that the text editing start.
1227 mImfManager.Activate();
1229 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1230 mImfManager.SetRestoreAfterFocusLost( true );
1232 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1236 notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
1239 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1241 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1244 void TextEditor::OnKeyInputFocusLost()
1246 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
1248 mImfManager.StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
1250 // The text editing is finished. Therefore the imf manager don't have restore activation.
1251 mImfManager.SetRestoreAfterFocusLost( false );
1253 // Notify that the text editing finish.
1254 mImfManager.Deactivate();
1256 mImfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
1258 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1262 notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
1265 mController->KeyboardFocusLostEvent();
1267 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1270 void TextEditor::OnTap( const TapGesture& gesture )
1272 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
1274 mImfManager.Activate();
1276 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1277 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1282 void TextEditor::OnPan( const PanGesture& gesture )
1284 mController->PanEvent( gesture.state, gesture.displacement );
1287 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1289 mImfManager.Activate();
1291 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1296 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1298 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1300 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1302 // Make sure ClearKeyInputFocus when only key is up
1303 if( event.state == KeyEvent::Up )
1305 ClearKeyInputFocus();
1311 return mController->KeyEvent( event );
1314 void TextEditor::RequestTextRelayout()
1319 void TextEditor::TextChanged()
1321 Dali::Toolkit::TextEditor handle( GetOwner() );
1322 mTextChangedSignal.Emit( handle );
1325 void TextEditor::MaxLengthReached()
1327 // Nothing to do as TextEditor doesn't emit a max length reached signal.
1330 void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1332 Dali::Toolkit::TextEditor handle( GetOwner() );
1334 Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
1336 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1338 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR );
1340 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1342 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY );
1344 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1346 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE );
1348 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1350 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1352 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1354 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1356 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1358 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE );
1360 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_LINE_SPACING ) )
1362 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING );
1364 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1366 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE );
1368 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1370 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW );
1372 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1374 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS );
1376 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1378 editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>( editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE );
1381 mInputStyleChangedSignal.Emit( handle, editorInputStyleMask );
1384 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1390 mClippingDecorationActors.push_back( actor );
1394 Self().Add( actor );
1399 void TextEditor::UpdateScrollBar()
1401 using namespace Dali;
1403 float scrollPosition;
1406 bool latestScrolled;
1408 if ( !mScrollBarEnabled )
1412 latestScrolled = mController->GetTextScrollInfo( scrollPosition, controlSize, layoutSize );
1413 if ( !latestScrolled || controlSize > layoutSize)
1418 CustomActor self = Self();
1421 mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::Vertical );
1422 mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::Variable );
1423 mScrollBar.SetParentOrigin( ParentOrigin::TOP_RIGHT );
1424 mScrollBar.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
1425 mScrollBar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1426 mScrollBar.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
1428 // Register the scroll position property
1429 Property::Index propertyScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION, scrollPosition );
1430 // Register the minimum scroll position property
1431 Property::Index propertyMinScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MIN, 0.0f );
1432 // Register the maximum scroll position property
1433 Property::Index propertyMaxScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize) );
1434 // Register the scroll content size property
1435 Property::Index propertyScrollContentSize = self.RegisterProperty( SCROLL_BAR_CONTENT_SIZE, layoutSize );
1437 mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1439 self.Add( mScrollBar );
1443 Property::Index propertyScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION );
1444 Property::Index propertyMaxScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION_MAX );
1445 Property::Index propertyScrollContentSize = self.GetPropertyIndex( SCROLL_BAR_CONTENT_SIZE );
1447 self.SetProperty( propertyScrollPosition, scrollPosition );
1448 self.SetProperty( propertyMaxScrollPosition, (layoutSize - controlSize) );
1449 self.SetProperty( propertyScrollContentSize, layoutSize );
1452 Actor indicator = mScrollBar.GetScrollIndicator();
1455 mAnimation.Stop(); // Cancel any animation
1459 mAnimation = Animation::New( mAnimationPeriod.durationSeconds );
1461 indicator.SetOpacity(1.0f);
1462 mAnimation.AnimateTo( Property( indicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod );
1466 void TextEditor::OnStageConnect( Dali::Actor actor )
1468 if ( mHasBeenStaged )
1470 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1474 mHasBeenStaged = true;
1478 ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1480 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1481 return mController->OnImfEvent( imfManager, imfEvent );
1484 void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1488 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1493 Scripting::CreatePropertyMap( image, map );
1499 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1501 mController->PasteClipboardItemEvent();
1504 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1506 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1508 // Just hide the grab handle when keyboard is hidden.
1509 if (!keyboardShown )
1511 mController->KeyboardFocusLostEvent();
1515 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1519 void TextEditor::OnStageConnection( int depth )
1521 // Sets the depth to the visuals inside the text's decorator.
1522 mDecorator->SetTextDepth( depth );
1524 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1526 // Call the Control::OnStageConnection() to set the depth of the background.
1527 Control::OnStageConnection( depth );
1530 bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
1535 void TextEditor::OnIdleSignal()
1537 // Emits the change of input style signals.
1538 mController->ProcessInputStyleChangedSignals();
1540 // Set the pointer to null as the callback manager deletes the callback after execute it.
1541 mIdleCallback = NULL;
1544 void TextEditor::ApplyScrollPosition()
1546 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1547 float scrollAmount = 0.0f;
1549 if ( mScrollAnimationEnabled )
1551 scrollAmount = mController->GetScrollAmountByUserInput();
1553 if ( mTextVerticalScroller )
1555 mTextVerticalScroller->CheckStartAnimation( mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount );
1557 else if ( Equals( scrollAmount, 0.0f, Math::MACHINE_EPSILON_1 ))
1559 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount );
1563 mTextVerticalScroller = Text::TextVerticalScroller::New();
1564 if ( !Equals( mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1 ))
1566 mTextVerticalScroller->SetDuration( mScrollAnimationDuration );
1568 mTextVerticalScroller->CheckStartAnimation( mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount );
1572 TextEditor::TextEditor()
1573 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1574 mAnimationPeriod( 0.0f, 0.0f ),
1575 mIdleCallback( NULL ),
1576 mAlignmentOffset( 0.f ),
1577 mScrollAnimationDuration( 0.f ),
1578 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1579 mHasBeenStaged( false ),
1580 mScrollAnimationEnabled( false ),
1581 mScrollBarEnabled( false )
1585 TextEditor::~TextEditor()
1587 UnparentAndReset( mStencil );
1589 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1591 // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1592 Adaptor::Get().RemoveIdle( mIdleCallback );
1596 } // namespace Internal
1598 } // namespace Toolkit