2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-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/adaptor-framework/virtual-keyboard.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-effects-style.h>
36 #include <dali-toolkit/internal/text/text-font-style.h>
37 #include <dali-toolkit/internal/text/text-view.h>
38 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40 using namespace Dali::Toolkit::Text;
51 namespace // unnamed namespace
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
58 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
59 } // unnamed namespace
64 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
66 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
67 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
68 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
70 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
75 return Toolkit::TextEditor::New();
78 // Setup properties, signals and actions using the type-registry.
79 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle", STRING, FONT_STYLE )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle", STRING, INPUT_FONT_STYLE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "underline", STRING, UNDERLINE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputUnderline", STRING, INPUT_UNDERLINE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "shadow", STRING, SHADOW )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputShadow", STRING, INPUT_SHADOW )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "emboss", STRING, EMBOSS )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputEmboss", STRING, INPUT_EMBOSS )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "outline", STRING, OUTLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputOutline", STRING, INPUT_OUTLINE )
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
124 DALI_TYPE_REGISTRATION_END()
128 Toolkit::TextEditor TextEditor::New()
130 // Create the implementation, temporarily owned by this handle on stack
131 IntrusivePtr< TextEditor > impl = new TextEditor();
133 // Pass ownership to CustomActor handle
134 Toolkit::TextEditor handle( *impl );
136 // Second-phase init of the implementation
137 // This can only be done after the CustomActor connection has been made...
143 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
145 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
147 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
152 TextEditor& impl( GetImpl( textEditor ) );
156 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
158 int backend = value.Get< int >();
159 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
161 if( impl.mRenderingBackend != backend )
163 impl.mRenderingBackend = backend;
164 impl.mRenderer.Reset();
165 impl.RequestTextRelayout();
169 case Toolkit::TextEditor::Property::TEXT:
171 if( impl.mController )
173 const std::string text = value.Get< std::string >();
174 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
176 impl.mController->SetText( text );
180 case Toolkit::TextEditor::Property::TEXT_COLOR:
182 if( impl.mController )
184 const Vector4 textColor = value.Get< Vector4 >();
185 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 );
187 if( impl.mController->GetTextColor() != textColor )
189 impl.mController->SetTextColor( textColor );
190 impl.mController->SetInputColor( textColor );
191 impl.mRenderer.Reset();
196 case Toolkit::TextEditor::Property::FONT_FAMILY:
198 if( impl.mController )
200 const std::string fontFamily = value.Get< std::string >();
201 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
202 impl.mController->SetDefaultFontFamily( fontFamily );
206 case Toolkit::TextEditor::Property::FONT_STYLE:
208 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
211 case Toolkit::TextEditor::Property::POINT_SIZE:
213 if( impl.mController )
215 const float pointSize = value.Get< float >();
216 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
218 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
220 impl.mController->SetDefaultPointSize( pointSize );
225 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
227 if( impl.mController )
229 const std::string alignStr = value.Get< std::string >();
230 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
232 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
233 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
234 HORIZONTAL_ALIGNMENT_STRING_TABLE,
235 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
238 impl.mController->SetHorizontalAlignment( alignment );
243 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
245 const float threshold = value.Get< float >();
246 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
248 if( impl.mDecorator )
250 impl.mDecorator->SetScrollThreshold( threshold );
254 case Toolkit::TextEditor::Property::SCROLL_SPEED:
256 const float speed = value.Get< float >();
257 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
259 if( impl.mDecorator )
261 impl.mDecorator->SetScrollSpeed( speed );
265 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
267 if( impl.mDecorator )
269 const Vector4 color = value.Get< Vector4 >();
270 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 );
272 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
273 impl.RequestTextRelayout();
277 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
279 if( impl.mDecorator )
281 const Vector4 color = value.Get< Vector4 >();
282 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 );
284 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
285 impl.RequestTextRelayout();
289 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
291 if( impl.mController )
293 const bool enable = value.Get< bool >();
294 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
296 impl.mController->SetEnableCursorBlink( enable );
297 impl.RequestTextRelayout();
301 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
303 if( impl.mDecorator )
305 const float interval = value.Get< float >();
306 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
308 impl.mDecorator->SetCursorBlinkInterval( interval );
312 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
314 if( impl.mDecorator )
316 const float duration = value.Get< float >();
317 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
319 impl.mDecorator->SetCursorBlinkDuration( duration );
323 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
325 if( impl.mDecorator )
327 const int width = value.Get< int >();
328 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
330 impl.mDecorator->SetCursorWidth( width );
331 impl.mController->GetLayoutEngine().SetCursorWidth( width );
335 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
337 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
338 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
340 if( impl.mDecorator )
342 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
343 impl.RequestTextRelayout();
347 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
349 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
350 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
352 if( impl.mDecorator )
354 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
355 impl.RequestTextRelayout();
359 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
361 const Image image = Scripting::NewImage( value );
363 if( impl.mDecorator && image )
365 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
366 impl.RequestTextRelayout();
370 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
372 const Image image = Scripting::NewImage( value );
374 if( impl.mDecorator && image )
376 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
377 impl.RequestTextRelayout();
381 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
383 const Image image = Scripting::NewImage( value );
385 if( impl.mDecorator && image )
387 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
388 impl.RequestTextRelayout();
392 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
394 const Image image = Scripting::NewImage( value );
396 if( impl.mDecorator && image )
398 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
399 impl.RequestTextRelayout();
403 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
405 const Image image = Scripting::NewImage( value );
407 if( impl.mDecorator && image )
409 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
410 impl.RequestTextRelayout();
414 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
416 const Image image = Scripting::NewImage( value );
418 if( impl.mDecorator && image )
420 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
421 impl.RequestTextRelayout();
425 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
427 const Vector4 color = value.Get< Vector4 >();
428 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 );
430 if( impl.mDecorator )
432 impl.mDecorator->SetHighlightColor( color );
433 impl.RequestTextRelayout();
437 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
439 if( impl.mDecorator )
441 const Rect<int> box = value.Get< Rect<int> >();
442 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 );
444 impl.mDecorator->SetBoundingBox( box );
445 impl.RequestTextRelayout();
449 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
451 if( impl.mController )
453 const bool enableMarkup = value.Get<bool>();
454 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
456 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
460 case Toolkit::TextEditor::Property::INPUT_COLOR:
462 if( impl.mController )
464 const Vector4 inputColor = value.Get< Vector4 >();
465 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 );
467 impl.mController->SetInputColor( inputColor );
471 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
473 if( impl.mController )
475 const std::string fontFamily = value.Get< std::string >();
476 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
477 impl.mController->SetInputFontFamily( fontFamily );
481 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
483 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
486 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
488 if( impl.mController )
490 const float pointSize = value.Get< float >();
491 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
492 impl.mController->SetInputFontPointSize( pointSize );
496 case Toolkit::TextEditor::Property::LINE_SPACING:
498 if( impl.mController )
500 const float lineSpacing = value.Get<float>();
501 impl.mController->SetDefaultLineSpacing( lineSpacing );
502 impl.mRenderer.Reset();
506 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
508 if( impl.mController )
510 const float lineSpacing = value.Get<float>();
511 impl.mController->SetInputLineSpacing( lineSpacing );
512 impl.mRenderer.Reset();
516 case Toolkit::TextEditor::Property::UNDERLINE:
518 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
521 impl.mRenderer.Reset();
525 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
527 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
530 impl.mRenderer.Reset();
534 case Toolkit::TextEditor::Property::SHADOW:
536 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
539 impl.mRenderer.Reset();
543 case Toolkit::TextEditor::Property::INPUT_SHADOW:
545 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
548 impl.mRenderer.Reset();
552 case Toolkit::TextEditor::Property::EMBOSS:
554 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
557 impl.mRenderer.Reset();
561 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
563 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
566 impl.mRenderer.Reset();
570 case Toolkit::TextEditor::Property::OUTLINE:
572 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
575 impl.mRenderer.Reset();
579 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
581 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
584 impl.mRenderer.Reset();
592 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
594 Property::Value value;
596 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
600 TextEditor& impl( GetImpl( textEditor ) );
604 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
606 value = impl.mRenderingBackend;
609 case Toolkit::TextEditor::Property::TEXT:
611 if( impl.mController )
614 impl.mController->GetText( text );
615 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
620 case Toolkit::TextEditor::Property::TEXT_COLOR:
622 if ( impl.mController )
624 value = impl.mController->GetTextColor();
628 case Toolkit::TextEditor::Property::FONT_FAMILY:
630 if( impl.mController )
632 value = impl.mController->GetDefaultFontFamily();
636 case Toolkit::TextEditor::Property::FONT_STYLE:
638 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
641 case Toolkit::TextEditor::Property::POINT_SIZE:
643 if( impl.mController )
645 value = impl.mController->GetDefaultPointSize();
649 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
651 if( impl.mController )
653 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
654 HORIZONTAL_ALIGNMENT_STRING_TABLE,
655 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
658 value = std::string( name );
663 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
665 if( impl.mDecorator )
667 value = impl.mDecorator->GetScrollThreshold();
671 case Toolkit::TextEditor::Property::SCROLL_SPEED:
673 if( impl.mDecorator )
675 value = impl.mDecorator->GetScrollSpeed();
679 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
681 if( impl.mDecorator )
683 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
687 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
689 if( impl.mDecorator )
691 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
695 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
697 value = impl.mController->GetEnableCursorBlink();
700 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
702 if( impl.mDecorator )
704 value = impl.mDecorator->GetCursorBlinkInterval();
708 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
710 if( impl.mDecorator )
712 value = impl.mDecorator->GetCursorBlinkDuration();
716 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
718 if( impl.mDecorator )
720 value = impl.mDecorator->GetCursorWidth();
724 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
726 if( impl.mDecorator )
728 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
731 value = image.GetUrl();
736 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
738 if( impl.mDecorator )
740 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
743 value = image.GetUrl();
748 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
750 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
753 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
755 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
758 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
760 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
763 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
765 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
768 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
770 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
773 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
775 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
778 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
780 if( impl.mDecorator )
782 value = impl.mDecorator->GetHighlightColor();
786 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
788 if( impl.mDecorator )
790 Rect<int> boundingBox;
791 impl.mDecorator->GetBoundingBox( boundingBox );
796 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
798 if( impl.mController )
800 value = impl.mController->IsMarkupProcessorEnabled();
804 case Toolkit::TextEditor::Property::INPUT_COLOR:
806 if( impl.mController )
808 value = impl.mController->GetInputColor();
812 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
814 if( impl.mController )
816 value = impl.mController->GetInputFontFamily();
820 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
822 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
825 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
827 if( impl.mController )
829 value = impl.mController->GetInputFontPointSize();
833 case Toolkit::TextEditor::Property::LINE_SPACING:
835 if( impl.mController )
837 value = impl.mController->GetDefaultLineSpacing();
841 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
843 if( impl.mController )
845 value = impl.mController->GetInputLineSpacing();
849 case Toolkit::TextEditor::Property::UNDERLINE:
851 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
854 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
856 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
859 case Toolkit::TextEditor::Property::SHADOW:
861 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
864 case Toolkit::TextEditor::Property::INPUT_SHADOW:
866 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
869 case Toolkit::TextEditor::Property::EMBOSS:
871 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
874 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
876 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
879 case Toolkit::TextEditor::Property::OUTLINE:
881 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
884 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
886 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
895 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
897 Dali::BaseHandle handle( object );
899 bool connected( true );
900 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
902 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
904 editor.TextChangedSignal().Connect( tracker, functor );
908 // signalName does not match any signal
915 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
917 return mTextChangedSignal;
920 void TextEditor::OnInitialize()
924 mController = Text::Controller::New( *this );
926 mDecorator = Text::Decorator::New( *mController,
929 mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX );
931 mController->EnableTextInput( mDecorator );
933 mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
935 // Forward input events to controller
936 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
937 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
939 self.TouchedSignal().Connect( this, &TextEditor::OnTouched );
941 // Set BoundingBox to stage size if not already set.
942 Rect<int> boundingBox;
943 mDecorator->GetBoundingBox( boundingBox );
945 if( boundingBox.IsEmpty() )
947 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
948 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
951 // Flip vertically the 'left' selection handle
952 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
954 // Fill-parent area by default
955 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
956 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
957 self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
960 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
962 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
966 case StyleChange::DEFAULT_FONT_CHANGE:
968 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
969 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
970 // Property system did not set the font so should update it.
971 mController->UpdateAfterFontChange( newFont );
975 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
977 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
979 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
981 // Property system did not set the PointSize so should update it.
982 // todo instruct text-controller to update model
986 case StyleChange::THEME_CHANGE:
988 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
994 Vector3 TextEditor::GetNaturalSize()
996 return mController->GetNaturalSize();
999 float TextEditor::GetHeightForWidth( float width )
1001 return mController->GetHeightForWidth( width );
1004 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
1006 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
1008 if( mController->Relayout( size ) ||
1011 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
1015 mDecorator->Relayout( size );
1020 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1023 EnableClipping( true, size );
1028 void TextEditor::RenderText()
1030 Actor self = Self();
1031 Actor renderableActor;
1034 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1037 if( renderableActor != mRenderableActor )
1039 UnparentAndReset( mRenderableActor );
1040 mRenderableActor = renderableActor;
1043 if( mRenderableActor )
1045 const Vector2& scrollOffset = mController->GetScrollPosition();
1047 mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
1049 Actor clipRootActor;
1052 clipRootActor = mClipper->GetRootActor();
1055 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1056 endIt = mClippingDecorationActors.end();
1064 clipRootActor.Add( actor );
1071 mClippingDecorationActors.clear();
1073 // Make sure the actor is parented correctly with/without clipping
1076 clipRootActor.Add( mRenderableActor );
1080 self.Add( mRenderableActor );
1085 void TextEditor::OnKeyInputFocusGained()
1087 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
1089 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
1091 ImfManager imfManager = ImfManager::Get();
1095 imfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
1097 // Notify that the text editing start.
1098 imfManager.Activate();
1100 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1101 imfManager.SetRestoreAfterFocusLost( true );
1104 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1108 notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
1111 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1113 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1116 void TextEditor::OnKeyInputFocusLost()
1118 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
1120 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
1122 ImfManager imfManager = ImfManager::Get();
1125 // The text editing is finished. Therefore the imf manager don't have restore activation.
1126 imfManager.SetRestoreAfterFocusLost( false );
1128 // Notify that the text editing finish.
1129 imfManager.Deactivate();
1131 imfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
1134 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1138 notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
1141 mController->KeyboardFocusLostEvent();
1143 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1146 void TextEditor::OnTap( const TapGesture& gesture )
1148 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
1150 // Show the keyboard if it was hidden.
1151 if (!VirtualKeyboard::IsVisible())
1153 VirtualKeyboard::Show();
1156 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1157 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1162 void TextEditor::OnPan( const PanGesture& gesture )
1164 mController->PanEvent( gesture.state, gesture.displacement );
1167 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1169 // Show the keyboard if it was hidden.
1170 if (!VirtualKeyboard::IsVisible())
1172 VirtualKeyboard::Show();
1175 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1180 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1182 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1184 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1186 ClearKeyInputFocus();
1190 return mController->KeyEvent( event );
1193 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1199 mClippingDecorationActors.push_back( actor );
1203 Self().Add( actor );
1208 void TextEditor::RequestTextRelayout()
1213 void TextEditor::TextChanged()
1215 Dali::Toolkit::TextEditor handle( GetOwner() );
1216 mTextChangedSignal.Emit( handle );
1219 void TextEditor::MaxLengthReached()
1221 // Nothing to do as TextEditor doesn't emit a max length reached signal.
1224 void TextEditor::OnStageConnect( Dali::Actor actor )
1226 if ( mHasBeenStaged )
1232 mHasBeenStaged = true;
1236 ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1239 return mController->OnImfEvent( imfManager, imfEvent );
1242 void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1246 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1251 Scripting::CreatePropertyMap( image, map );
1257 void TextEditor::EnableClipping( bool clipping, const Vector2& size )
1261 // Not worth to created clip actor if width or height is equal to zero.
1262 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1266 Actor self = Self();
1268 mClipper = Clipper::New( size );
1269 self.Add( mClipper->GetRootActor() );
1270 self.Add( mClipper->GetImageActor() );
1272 else if ( mClipper )
1274 mClipper->Refresh( size );
1280 // Note - this will automatically remove the root & image actors
1285 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1287 mController->PasteClipboardItemEvent();
1290 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1292 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1294 // Just hide the grab handle when keyboard is hidden.
1295 if (!keyboardShown )
1297 mController->KeyboardFocusLostEvent();
1301 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1305 void TextEditor::OnStageConnection( int depth )
1307 // Call the Control::OnStageConnection() to set the depth of the background.
1308 Control::OnStageConnection( depth );
1310 // Sets the depth to the renderers inside the text's decorator.
1311 mDecorator->SetTextDepth( depth );
1313 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1316 bool TextEditor::OnTouched( Actor actor, const TouchEvent& event )
1321 TextEditor::TextEditor()
1322 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1323 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1324 mHasBeenStaged( false )
1328 TextEditor::~TextEditor()
1333 } // namespace Internal
1335 } // namespace Toolkit