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 const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
60 } // unnamed namespace
65 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
67 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
68 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
69 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
71 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
76 return Toolkit::TextEditor::New();
79 // Setup properties, signals and actions using the type-registry.
80 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text", STRING, TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontStyle", STRING, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollSpeed", FLOAT, SCROLL_SPEED )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "cursorWidth", INTEGER, CURSOR_WIDTH )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputColor", VECTOR4, INPUT_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputFontStyle", STRING, INPUT_FONT_STYLE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineSpacing", FLOAT, LINE_SPACING )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputLineSpacing", FLOAT, INPUT_LINE_SPACING )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "underline", STRING, UNDERLINE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputUnderline", STRING, INPUT_UNDERLINE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "shadow", STRING, SHADOW )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputShadow", STRING, INPUT_SHADOW )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "emboss", STRING, EMBOSS )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputEmboss", STRING, INPUT_EMBOSS )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "outline", STRING, OUTLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "inputOutline", STRING, INPUT_OUTLINE )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
125 DALI_TYPE_REGISTRATION_END()
129 Toolkit::TextEditor TextEditor::New()
131 // Create the implementation, temporarily owned by this handle on stack
132 IntrusivePtr< TextEditor > impl = new TextEditor();
134 // Pass ownership to CustomActor handle
135 Toolkit::TextEditor handle( *impl );
137 // Second-phase init of the implementation
138 // This can only be done after the CustomActor connection has been made...
144 void TextEditor::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
146 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
148 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
153 TextEditor& impl( GetImpl( textEditor ) );
157 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
159 int backend = value.Get< int >();
160 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
162 if( impl.mRenderingBackend != backend )
164 impl.mRenderingBackend = backend;
165 impl.mRenderer.Reset();
166 impl.RequestTextRelayout();
170 case Toolkit::TextEditor::Property::TEXT:
172 if( impl.mController )
174 const std::string text = value.Get< std::string >();
175 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() );
177 impl.mController->SetText( text );
181 case Toolkit::TextEditor::Property::TEXT_COLOR:
183 if( impl.mController )
185 const Vector4 textColor = value.Get< Vector4 >();
186 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 );
188 if( impl.mController->GetTextColor() != textColor )
190 impl.mController->SetTextColor( textColor );
191 impl.mController->SetInputColor( textColor );
192 impl.mRenderer.Reset();
197 case Toolkit::TextEditor::Property::FONT_FAMILY:
199 if( impl.mController )
201 const std::string fontFamily = value.Get< std::string >();
202 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
203 impl.mController->SetDefaultFontFamily( fontFamily );
207 case Toolkit::TextEditor::Property::FONT_STYLE:
209 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
212 case Toolkit::TextEditor::Property::POINT_SIZE:
214 if( impl.mController )
216 const float pointSize = value.Get< float >();
217 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
219 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
221 impl.mController->SetDefaultPointSize( pointSize );
226 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
228 if( impl.mController )
230 const std::string alignStr = value.Get< std::string >();
231 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
233 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
234 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
235 HORIZONTAL_ALIGNMENT_STRING_TABLE,
236 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
239 impl.mController->SetHorizontalAlignment( alignment );
244 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
246 const float threshold = value.Get< float >();
247 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
249 if( impl.mDecorator )
251 impl.mDecorator->SetScrollThreshold( threshold );
255 case Toolkit::TextEditor::Property::SCROLL_SPEED:
257 const float speed = value.Get< float >();
258 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
260 if( impl.mDecorator )
262 impl.mDecorator->SetScrollSpeed( speed );
266 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
268 if( impl.mDecorator )
270 const Vector4 color = value.Get< Vector4 >();
271 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 );
273 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
274 impl.RequestTextRelayout();
278 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
280 if( impl.mDecorator )
282 const Vector4 color = value.Get< Vector4 >();
283 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 );
285 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
286 impl.RequestTextRelayout();
290 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
292 if( impl.mController )
294 const bool enable = value.Get< bool >();
295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
297 impl.mController->SetEnableCursorBlink( enable );
298 impl.RequestTextRelayout();
302 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
304 if( impl.mDecorator )
306 const float interval = value.Get< float >();
307 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
309 impl.mDecorator->SetCursorBlinkInterval( interval );
313 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
315 if( impl.mDecorator )
317 const float duration = value.Get< float >();
318 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
320 impl.mDecorator->SetCursorBlinkDuration( duration );
324 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
326 if( impl.mDecorator )
328 const int width = value.Get< int >();
329 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
331 impl.mDecorator->SetCursorWidth( width );
332 impl.mController->GetLayoutEngine().SetCursorWidth( width );
336 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
338 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
339 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
341 if( impl.mDecorator )
343 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
344 impl.RequestTextRelayout();
348 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
350 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
353 if( impl.mDecorator )
355 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
356 impl.RequestTextRelayout();
360 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
362 const Image image = Scripting::NewImage( value );
364 if( impl.mDecorator && image )
366 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
367 impl.RequestTextRelayout();
371 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
373 const Image image = Scripting::NewImage( value );
375 if( impl.mDecorator && image )
377 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
378 impl.RequestTextRelayout();
382 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
384 const Image image = Scripting::NewImage( value );
386 if( impl.mDecorator && image )
388 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
389 impl.RequestTextRelayout();
393 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
395 const Image image = Scripting::NewImage( value );
397 if( impl.mDecorator && image )
399 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
400 impl.RequestTextRelayout();
404 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
406 const Image image = Scripting::NewImage( value );
408 if( impl.mDecorator && image )
410 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
411 impl.RequestTextRelayout();
415 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
417 const Image image = Scripting::NewImage( value );
419 if( impl.mDecorator && image )
421 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
422 impl.RequestTextRelayout();
426 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
428 const Vector4 color = value.Get< Vector4 >();
429 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 );
431 if( impl.mDecorator )
433 impl.mDecorator->SetHighlightColor( color );
434 impl.RequestTextRelayout();
438 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
440 if( impl.mDecorator )
442 const Rect<int> box = value.Get< Rect<int> >();
443 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 );
445 impl.mDecorator->SetBoundingBox( box );
446 impl.RequestTextRelayout();
450 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
452 if( impl.mController )
454 const bool enableMarkup = value.Get<bool>();
455 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
457 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
461 case Toolkit::TextEditor::Property::INPUT_COLOR:
463 if( impl.mController )
465 const Vector4 inputColor = value.Get< Vector4 >();
466 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 );
468 impl.mController->SetInputColor( inputColor );
472 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
474 if( impl.mController )
476 const std::string fontFamily = value.Get< std::string >();
477 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
478 impl.mController->SetInputFontFamily( fontFamily );
482 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
484 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
487 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
489 if( impl.mController )
491 const float pointSize = value.Get< float >();
492 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
493 impl.mController->SetInputFontPointSize( pointSize );
497 case Toolkit::TextEditor::Property::LINE_SPACING:
499 if( impl.mController )
501 const float lineSpacing = value.Get<float>();
502 impl.mController->SetDefaultLineSpacing( lineSpacing );
503 impl.mRenderer.Reset();
507 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
509 if( impl.mController )
511 const float lineSpacing = value.Get<float>();
512 impl.mController->SetInputLineSpacing( lineSpacing );
513 impl.mRenderer.Reset();
517 case Toolkit::TextEditor::Property::UNDERLINE:
519 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
522 impl.mRenderer.Reset();
526 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
528 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
531 impl.mRenderer.Reset();
535 case Toolkit::TextEditor::Property::SHADOW:
537 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
540 impl.mRenderer.Reset();
544 case Toolkit::TextEditor::Property::INPUT_SHADOW:
546 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
549 impl.mRenderer.Reset();
553 case Toolkit::TextEditor::Property::EMBOSS:
555 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
558 impl.mRenderer.Reset();
562 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
564 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
567 impl.mRenderer.Reset();
571 case Toolkit::TextEditor::Property::OUTLINE:
573 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
576 impl.mRenderer.Reset();
580 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
582 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
585 impl.mRenderer.Reset();
593 Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index index )
595 Property::Value value;
597 Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast( Dali::BaseHandle( object ) );
601 TextEditor& impl( GetImpl( textEditor ) );
605 case Toolkit::TextEditor::Property::RENDERING_BACKEND:
607 value = impl.mRenderingBackend;
610 case Toolkit::TextEditor::Property::TEXT:
612 if( impl.mController )
615 impl.mController->GetText( text );
616 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() );
621 case Toolkit::TextEditor::Property::TEXT_COLOR:
623 if ( impl.mController )
625 value = impl.mController->GetTextColor();
629 case Toolkit::TextEditor::Property::FONT_FAMILY:
631 if( impl.mController )
633 value = impl.mController->GetDefaultFontFamily();
637 case Toolkit::TextEditor::Property::FONT_STYLE:
639 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
642 case Toolkit::TextEditor::Property::POINT_SIZE:
644 if( impl.mController )
646 value = impl.mController->GetDefaultPointSize();
650 case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT:
652 if( impl.mController )
654 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
655 HORIZONTAL_ALIGNMENT_STRING_TABLE,
656 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
659 value = std::string( name );
664 case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
666 if( impl.mDecorator )
668 value = impl.mDecorator->GetScrollThreshold();
672 case Toolkit::TextEditor::Property::SCROLL_SPEED:
674 if( impl.mDecorator )
676 value = impl.mDecorator->GetScrollSpeed();
680 case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR:
682 if( impl.mDecorator )
684 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
688 case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR:
690 if( impl.mDecorator )
692 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
696 case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK:
698 value = impl.mController->GetEnableCursorBlink();
701 case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL:
703 if( impl.mDecorator )
705 value = impl.mDecorator->GetCursorBlinkInterval();
709 case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION:
711 if( impl.mDecorator )
713 value = impl.mDecorator->GetCursorBlinkDuration();
717 case Toolkit::TextEditor::Property::CURSOR_WIDTH:
719 if( impl.mDecorator )
721 value = impl.mDecorator->GetCursorWidth();
725 case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
727 if( impl.mDecorator )
729 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
732 value = image.GetUrl();
737 case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
739 if( impl.mDecorator )
741 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
744 value = image.GetUrl();
749 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
751 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
754 case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
756 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
759 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
761 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
764 case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
766 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
769 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
771 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
774 case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
776 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
779 case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR:
781 if( impl.mDecorator )
783 value = impl.mDecorator->GetHighlightColor();
787 case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX:
789 if( impl.mDecorator )
791 Rect<int> boundingBox;
792 impl.mDecorator->GetBoundingBox( boundingBox );
797 case Toolkit::TextEditor::Property::ENABLE_MARKUP:
799 if( impl.mController )
801 value = impl.mController->IsMarkupProcessorEnabled();
805 case Toolkit::TextEditor::Property::INPUT_COLOR:
807 if( impl.mController )
809 value = impl.mController->GetInputColor();
813 case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY:
815 if( impl.mController )
817 value = impl.mController->GetInputFontFamily();
821 case Toolkit::TextEditor::Property::INPUT_FONT_STYLE:
823 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
826 case Toolkit::TextEditor::Property::INPUT_POINT_SIZE:
828 if( impl.mController )
830 value = impl.mController->GetInputFontPointSize();
834 case Toolkit::TextEditor::Property::LINE_SPACING:
836 if( impl.mController )
838 value = impl.mController->GetDefaultLineSpacing();
842 case Toolkit::TextEditor::Property::INPUT_LINE_SPACING:
844 if( impl.mController )
846 value = impl.mController->GetInputLineSpacing();
850 case Toolkit::TextEditor::Property::UNDERLINE:
852 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
855 case Toolkit::TextEditor::Property::INPUT_UNDERLINE:
857 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
860 case Toolkit::TextEditor::Property::SHADOW:
862 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
865 case Toolkit::TextEditor::Property::INPUT_SHADOW:
867 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
870 case Toolkit::TextEditor::Property::EMBOSS:
872 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
875 case Toolkit::TextEditor::Property::INPUT_EMBOSS:
877 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
880 case Toolkit::TextEditor::Property::OUTLINE:
882 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
885 case Toolkit::TextEditor::Property::INPUT_OUTLINE:
887 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
896 bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
898 Dali::BaseHandle handle( object );
900 bool connected( true );
901 Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast( handle );
903 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
905 editor.TextChangedSignal().Connect( tracker, functor );
909 // signalName does not match any signal
916 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
918 return mTextChangedSignal;
921 void TextEditor::OnInitialize()
925 mController = Text::Controller::New( *this );
927 mDecorator = Text::Decorator::New( *mController,
930 mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX );
932 // Enables the text input.
933 mController->EnableTextInput( mDecorator );
935 // Enables the vertical scrolling after the text input has been enabled.
936 mController->SetVerticalScrollEnabled( true );
938 // Disables the horizontal scrolling.
939 mController->SetHorizontalScrollEnabled( false );
941 mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
943 // Enable the smooth handle panning.
944 mController->SetSmoothHandlePanEnabled( true );
946 // Forward input events to controller
947 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
948 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
950 self.TouchSignal().Connect( this, &TextEditor::OnTouched );
952 // Set BoundingBox to stage size if not already set.
953 Rect<int> boundingBox;
954 mDecorator->GetBoundingBox( boundingBox );
956 if( boundingBox.IsEmpty() )
958 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
959 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
962 // Whether to flip the selection handles as soon as they cross.
963 mDecorator->FlipSelectionHandlesOnCrossEnabled( true );
965 // Set the default scroll speed.
966 mDecorator->SetScrollSpeed( DEFAULT_SCROLL_SPEED );
968 // Fill-parent area by default
969 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
970 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
971 self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
974 void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
976 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
980 case StyleChange::DEFAULT_FONT_CHANGE:
982 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
983 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
984 // Property system did not set the font so should update it.
985 mController->UpdateAfterFontChange( newFont );
989 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
991 DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
993 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
995 // Property system did not set the PointSize so should update it.
996 // todo instruct text-controller to update model
1000 case StyleChange::THEME_CHANGE:
1002 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1008 Vector3 TextEditor::GetNaturalSize()
1010 return mController->GetNaturalSize();
1013 float TextEditor::GetHeightForWidth( float width )
1015 return mController->GetHeightForWidth( width );
1018 void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container )
1020 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
1022 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1024 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1027 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get() );
1030 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1032 mDecorator->Relayout( size );
1037 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1040 EnableClipping( true, size );
1041 RenderText( updateTextType );
1045 void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
1047 Actor self = Self();
1048 Actor renderableActor;
1050 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1054 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1057 if( renderableActor != mRenderableActor )
1059 UnparentAndReset( mRenderableActor );
1060 mRenderableActor = renderableActor;
1064 if( mRenderableActor )
1066 const Vector2& scrollOffset = mController->GetScrollPosition();
1068 mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
1070 Actor clipRootActor;
1073 clipRootActor = mClipper->GetRootActor();
1076 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1077 endIt = mClippingDecorationActors.end();
1085 clipRootActor.Add( actor );
1092 mClippingDecorationActors.clear();
1094 // Make sure the actor is parented correctly with/without clipping
1097 clipRootActor.Add( mRenderableActor );
1101 self.Add( mRenderableActor );
1106 void TextEditor::OnKeyInputFocusGained()
1108 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
1110 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
1112 ImfManager imfManager = ImfManager::Get();
1116 imfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
1118 // Notify that the text editing start.
1119 imfManager.Activate();
1121 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1122 imfManager.SetRestoreAfterFocusLost( true );
1125 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1129 notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
1132 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1134 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1137 void TextEditor::OnKeyInputFocusLost()
1139 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
1141 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
1143 ImfManager imfManager = ImfManager::Get();
1146 // The text editing is finished. Therefore the imf manager don't have restore activation.
1147 imfManager.SetRestoreAfterFocusLost( false );
1149 // Notify that the text editing finish.
1150 imfManager.Deactivate();
1152 imfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
1155 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1159 notifier.ContentSelectedSignal().Disconnect( this, &TextEditor::OnClipboardTextSelected );
1162 mController->KeyboardFocusLostEvent();
1164 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1167 void TextEditor::OnTap( const TapGesture& gesture )
1169 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
1171 // Show the keyboard if it was hidden.
1172 if (!VirtualKeyboard::IsVisible())
1174 VirtualKeyboard::Show();
1177 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1178 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1183 void TextEditor::OnPan( const PanGesture& gesture )
1185 mController->PanEvent( gesture.state, gesture.displacement );
1188 void TextEditor::OnLongPress( const LongPressGesture& gesture )
1190 // Show the keyboard if it was hidden.
1191 if (!VirtualKeyboard::IsVisible())
1193 VirtualKeyboard::Show();
1196 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1201 bool TextEditor::OnKeyEvent( const KeyEvent& event )
1203 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1205 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1207 ClearKeyInputFocus();
1211 return mController->KeyEvent( event );
1214 void TextEditor::AddDecoration( Actor& actor, bool needsClipping )
1220 mClippingDecorationActors.push_back( actor );
1224 Self().Add( actor );
1229 void TextEditor::RequestTextRelayout()
1234 void TextEditor::TextChanged()
1236 Dali::Toolkit::TextEditor handle( GetOwner() );
1237 mTextChangedSignal.Emit( handle );
1240 void TextEditor::MaxLengthReached()
1242 // Nothing to do as TextEditor doesn't emit a max length reached signal.
1245 void TextEditor::OnStageConnect( Dali::Actor actor )
1247 if ( mHasBeenStaged )
1249 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1253 mHasBeenStaged = true;
1257 ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1259 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1260 return mController->OnImfEvent( imfManager, imfEvent );
1263 void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1267 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1272 Scripting::CreatePropertyMap( image, map );
1278 void TextEditor::EnableClipping( bool clipping, const Vector2& size )
1282 // Not worth to created clip actor if width or height is equal to zero.
1283 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1287 Actor self = Self();
1289 mClipper = Clipper::New( size );
1290 self.Add( mClipper->GetRootActor() );
1291 self.Add( mClipper->GetImageView() );
1293 else if ( mClipper )
1295 mClipper->Refresh( size );
1301 // Note - this will automatically remove the root actor & the image view
1306 void TextEditor::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1308 mController->PasteClipboardItemEvent();
1311 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1313 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1315 // Just hide the grab handle when keyboard is hidden.
1316 if (!keyboardShown )
1318 mController->KeyboardFocusLostEvent();
1322 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1326 void TextEditor::OnStageConnection( int depth )
1328 // Call the Control::OnStageConnection() to set the depth of the background.
1329 Control::OnStageConnection( depth );
1331 // Sets the depth to the visuals inside the text's decorator.
1332 mDecorator->SetTextDepth( depth );
1334 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1337 bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
1342 TextEditor::TextEditor()
1343 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1344 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1345 mHasBeenStaged( false )
1349 TextEditor::~TextEditor()
1354 } // namespace Internal
1356 } // namespace Toolkit