X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-editor-impl.cpp;h=74f37323a3d707a03b772521b90eb41c516c6ef7;hp=b022757b3d610b88622ce87eb38de033fe9eff11;hb=8a647e87a01c5c78451653c1264a9eea81ac9b20;hpb=ef15505c94dffeb0639c91d9d3cd374918c21c4f diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index b022757..74f3732 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -138,6 +140,10 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING ) +DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -190,6 +196,8 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P if( textEditor ) { TextEditor& impl( GetImpl( textEditor ) ); + DALI_ASSERT_DEBUG( impl.mController && "No text contoller" ); + DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" ); switch( index ) { @@ -208,39 +216,30 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::TextEditor::Property::TEXT: { - if( impl.mController ) - { - const std::string& text = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() ); + const std::string& text = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p TEXT %s\n", impl.mController.Get(), text.c_str() ); - impl.mController->SetText( text ); - } + impl.mController->SetText( text ); break; } case Toolkit::TextEditor::Property::TEXT_COLOR: { - if( impl.mController ) - { - const Vector4& textColor = value.Get< Vector4 >(); - 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 ); + const Vector4& textColor = value.Get< Vector4 >(); + 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 ); - if( impl.mController->GetDefaultColor() != textColor ) - { - impl.mController->SetDefaultColor( textColor ); - impl.mController->SetInputColor( textColor ); - impl.mRenderer.Reset(); - } + if( impl.mController->GetDefaultColor() != textColor ) + { + impl.mController->SetDefaultColor( textColor ); + impl.mController->SetInputColor( textColor ); + impl.mRenderer.Reset(); } break; } case Toolkit::TextEditor::Property::FONT_FAMILY: { - if( impl.mController ) - { - const std::string& fontFamily = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() ); - impl.mController->SetDefaultFontFamily( fontFamily ); - } + const std::string& fontFamily = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() ); + impl.mController->SetDefaultFontFamily( fontFamily ); break; } case Toolkit::TextEditor::Property::FONT_STYLE: @@ -250,28 +249,22 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::TextEditor::Property::POINT_SIZE: { - if( impl.mController ) - { - const float pointSize = value.Get< float >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize ); + const float pointSize = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p POINT_SIZE %f\n", impl.mController.Get(), pointSize ); - if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) ) - { - impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE ); - } + if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) ) + { + impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE ); } break; } case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT: { - if( impl.mController ) + Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) ) { - Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set - if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) ) - { - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment ); - impl.mController->SetHorizontalAlignment( alignment ); - } + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment ); + impl.mController->SetHorizontalAlignment( alignment ); } break; } @@ -280,10 +273,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P const float threshold = value.Get< float >(); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold ); - if( impl.mDecorator ) - { - impl.mDecorator->SetScrollThreshold( threshold ); - } + impl.mDecorator->SetScrollThreshold( threshold ); break; } case Toolkit::TextEditor::Property::SCROLL_SPEED: @@ -291,80 +281,59 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P const float speed = value.Get< float >(); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p SCROLL_SPEED %f\n", impl.mController.Get(), speed ); - if( impl.mDecorator ) - { - impl.mDecorator->SetScrollSpeed( speed ); - } + impl.mDecorator->SetScrollSpeed( speed ); break; } case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR: { - if( impl.mDecorator ) - { - const Vector4& color = value.Get< Vector4 >(); - 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 ); + const Vector4& color = value.Get< Vector4 >(); + 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 ); - impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color ); - impl.RequestTextRelayout(); - } + impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color ); + impl.RequestTextRelayout(); break; } case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR: { - if( impl.mDecorator ) - { - const Vector4& color = value.Get< Vector4 >(); - 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 ); + const Vector4& color = value.Get< Vector4 >(); + 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 ); - impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color ); - impl.RequestTextRelayout(); - } + impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color ); + impl.RequestTextRelayout(); break; } case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK: { - if( impl.mController ) - { - const bool enable = value.Get< bool >(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable ); + const bool enable = value.Get< bool >(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable ); - impl.mController->SetEnableCursorBlink( enable ); - impl.RequestTextRelayout(); - } + impl.mController->SetEnableCursorBlink( enable ); + impl.RequestTextRelayout(); break; } case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL: { - if( impl.mDecorator ) - { - const float interval = value.Get< float >(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval ); + const float interval = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval ); - impl.mDecorator->SetCursorBlinkInterval( interval ); - } + impl.mDecorator->SetCursorBlinkInterval( interval ); break; } case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION: { - if( impl.mDecorator ) - { - const float duration = value.Get< float >(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration ); + const float duration = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration ); - impl.mDecorator->SetCursorBlinkDuration( duration ); - } + impl.mDecorator->SetCursorBlinkDuration( duration ); break; } case Toolkit::TextEditor::Property::CURSOR_WIDTH: { - if( impl.mDecorator ) - { - const int width = value.Get< int >(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width ); + const int width = value.Get< int >(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p CURSOR_WIDTH %d\n", impl.mController.Get(), width ); - impl.mDecorator->SetCursorWidth( width ); - impl.mController->GetLayoutEngine().SetCursorWidth( width ); - } + impl.mDecorator->SetCursorWidth( width ); + impl.mController->GetLayoutEngine().SetCursorWidth( width ); break; } case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE: @@ -372,7 +341,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P const std::string imageFileName = value.Get< std::string >(); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() ); - if( impl.mDecorator && imageFileName.size() ) + if( imageFileName.size() ) { impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName ); impl.RequestTextRelayout(); @@ -384,7 +353,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P const std::string imageFileName = value.Get< std::string >(); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() ); - if( impl.mDecorator && imageFileName.size() ) + if( imageFileName.size() ) { impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName ); impl.RequestTextRelayout(); @@ -395,7 +364,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && filename.size() ) + if( filename.size() ) { impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); @@ -406,7 +375,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && filename.size() ) + if( filename.size() ) { impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); @@ -417,7 +386,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && filename.size() ) + if( filename.size() ) { impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename ); impl.RequestTextRelayout(); @@ -428,7 +397,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && filename.size() ) + if( filename.size() ) { impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename ); impl.RequestTextRelayout(); @@ -439,7 +408,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && filename.size() ) + if( filename.size() ) { impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); @@ -450,7 +419,7 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && filename.size() ) + if( filename.size() ) { impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); @@ -462,55 +431,40 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P const Vector4 color = value.Get< Vector4 >(); 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 ); - if( impl.mDecorator ) - { - impl.mDecorator->SetHighlightColor( color ); - impl.RequestTextRelayout(); - } + impl.mDecorator->SetHighlightColor( color ); + impl.RequestTextRelayout(); break; } case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX: { - if( impl.mDecorator ) - { - const Rect& box = value.Get< Rect >(); - 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 ); + const Rect& box = value.Get< Rect >(); + 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 ); - impl.mDecorator->SetBoundingBox( box ); - impl.RequestTextRelayout(); - } + impl.mDecorator->SetBoundingBox( box ); + impl.RequestTextRelayout(); break; } case Toolkit::TextEditor::Property::ENABLE_MARKUP: { - if( impl.mController ) - { - const bool enableMarkup = value.Get(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup ); + const bool enableMarkup = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup ); - impl.mController->SetMarkupProcessorEnabled( enableMarkup ); - } + impl.mController->SetMarkupProcessorEnabled( enableMarkup ); break; } case Toolkit::TextEditor::Property::INPUT_COLOR: { - if( impl.mController ) - { - const Vector4& inputColor = value.Get< Vector4 >(); - 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 ); + const Vector4& inputColor = value.Get< Vector4 >(); + 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 ); - impl.mController->SetInputColor( inputColor ); - } + impl.mController->SetInputColor( inputColor ); break; } case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY: { - if( impl.mController ) - { - const std::string& fontFamily = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() ); - impl.mController->SetInputFontFamily( fontFamily ); - } + const std::string& fontFamily = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() ); + impl.mController->SetInputFontFamily( fontFamily ); break; } case Toolkit::TextEditor::Property::INPUT_FONT_STYLE: @@ -520,38 +474,28 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::TextEditor::Property::INPUT_POINT_SIZE: { - if( impl.mController ) - { - const float pointSize = value.Get< float >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize ); - impl.mController->SetInputFontPointSize( pointSize ); - } + const float pointSize = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize ); + impl.mController->SetInputFontPointSize( pointSize ); break; } case Toolkit::TextEditor::Property::LINE_SPACING: { - if( impl.mController ) - { - - // The line spacing isn't supported by the TextEditor. Since it's supported - // by the TextLabel for now it must be ignored. The property is being shadowed - // locally so its value isn't affected. - const float lineSpacing = value.Get(); - impl.mLineSpacing = lineSpacing; - // set it to 0.0 due to missing implementation - impl.mController->SetDefaultLineSpacing( 0.0f ); - impl.mRenderer.Reset(); - } + // The line spacing isn't supported by the TextEditor. Since it's supported + // by the TextLabel for now it must be ignored. The property is being shadowed + // locally so its value isn't affected. + const float lineSpacing = value.Get(); + impl.mLineSpacing = lineSpacing; + // set it to 0.0 due to missing implementation + impl.mController->SetDefaultLineSpacing( 0.0f ); + impl.mRenderer.Reset(); break; } case Toolkit::TextEditor::Property::INPUT_LINE_SPACING: { - if( impl.mController ) - { - const float lineSpacing = value.Get(); - impl.mController->SetInputLineSpacing( lineSpacing ); - impl.mRenderer.Reset(); - } + const float lineSpacing = value.Get(); + impl.mController->SetInputLineSpacing( lineSpacing ); + impl.mRenderer.Reset(); break; } case Toolkit::TextEditor::Property::UNDERLINE: @@ -672,52 +616,40 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::TextEditor::Property::PIXEL_SIZE: { - if( impl.mController ) - { - const float pixelSize = value.Get< float >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize ); + const float pixelSize = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize ); - if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) ) - { - impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE ); - } + if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) ) + { + impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE ); } break; } case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT: { - if( impl.mController ) - { - const std::string& text = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnPropertySet %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() ); + const std::string& text = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnPropertySet %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() ); - impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text ); - } + impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text ); break; } case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR: { - if( impl.mController ) - { - const Vector4& textColor = value.Get< Vector4 >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a ); + const Vector4& textColor = value.Get< Vector4 >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a ); - if( impl.mController->GetPlaceholderTextColor() != textColor ) - { - impl.mController->SetPlaceholderTextColor( textColor ); - impl.mRenderer.Reset(); - } + if( impl.mController->GetPlaceholderTextColor() != textColor ) + { + impl.mController->SetPlaceholderTextColor( textColor ); + impl.mRenderer.Reset(); } break; } case Toolkit::TextEditor::Property::ENABLE_SELECTION: { - if( impl.mController ) - { - const bool enableSelection = value.Get< bool >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection ); - impl.mController->SetSelectionEnabled( enableSelection ); - } + const bool enableSelection = value.Get< bool >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection ); + impl.mController->SetSelectionEnabled( enableSelection ); break; } case Toolkit::TextEditor::Property::PLACEHOLDER: @@ -731,56 +663,62 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::TextEditor::Property::LINE_WRAP_MODE: { - if( impl.mController ) + Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( GetLineWrapModeEnumeration( value, lineWrapMode ) ) { - Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set - if( GetLineWrapModeEnumeration( value, lineWrapMode ) ) - { - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode ); - impl.mController->SetLineWrapMode( lineWrapMode ); - } + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode ); + impl.mController->SetLineWrapMode( lineWrapMode ); } break; } case Toolkit::DevelTextEditor::Property::ENABLE_SHIFT_SELECTION: { - if( impl.mController ) - { - const bool shiftSelection = value.Get(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection ); + const bool shiftSelection = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection ); - impl.mController->SetShiftSelectionEnabled( shiftSelection ); - } + impl.mController->SetShiftSelectionEnabled( shiftSelection ); break; } case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE: { - if( impl.mController ) - { - const bool grabHandleEnabled = value.Get(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled ); + const bool grabHandleEnabled = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled ); - impl.mController->SetGrabHandleEnabled( grabHandleEnabled ); - } + impl.mController->SetGrabHandleEnabled( grabHandleEnabled ); break; } case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - if( impl.mController ) - { - impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >()); - } + impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >()); break; } case Toolkit::DevelTextEditor::Property::MAX_LENGTH: { - if( impl.mController ) - { - const int max = value.Get< int >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p MAX_LENGTH %d\n", impl.mController.Get(), max ); + const int max = value.Get< int >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p MAX_LENGTH %d\n", impl.mController.Get(), max ); - impl.mController->SetMaximumNumberOfCharacters( max ); - } + impl.mController->SetMaximumNumberOfCharacters( max ); + break; + } + case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_START: + { + uint32_t start = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start ); + impl.SetTextSelectionRange( &start, nullptr ); + break; + } + case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_END: + { + uint32_t end = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end ); + impl.SetTextSelectionRange( nullptr, &end ); + break; + } + case Toolkit::DevelTextEditor::Property::ENABLE_EDITING: + { + const bool editable = value.Get< bool >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_EDITING %d\n", impl.mController.Get(), editable ); + impl.SetEditable( editable ); break; } } // switch @@ -796,6 +734,8 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind if( textEditor ) { TextEditor& impl( GetImpl( textEditor ) ); + DALI_ASSERT_DEBUG( impl.mController && "No text contoller" ); + DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" ); switch( index ) { @@ -806,29 +746,20 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::TEXT: { - if( impl.mController ) - { - std::string text; - impl.mController->GetText( text ); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() ); - value = text; - } + std::string text; + impl.mController->GetText( text ); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p returning text: %s\n", impl.mController.Get(), text.c_str() ); + value = text; break; } case Toolkit::TextEditor::Property::TEXT_COLOR: { - if ( impl.mController ) - { - value = impl.mController->GetDefaultColor(); - } + value = impl.mController->GetDefaultColor(); break; } case Toolkit::TextEditor::Property::FONT_FAMILY: { - if( impl.mController ) - { - value = impl.mController->GetDefaultFontFamily(); - } + value = impl.mController->GetDefaultFontFamily(); break; } case Toolkit::TextEditor::Property::FONT_STYLE: @@ -838,54 +769,36 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::POINT_SIZE: { - if( impl.mController ) - { - value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ); - } + value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ); break; } case Toolkit::TextEditor::Property::HORIZONTAL_ALIGNMENT: { - if( impl.mController ) + const char* name = GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() ); + if( name ) { - const char* name = GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() ); - if( name ) - { - value = std::string( name ); - } + value = std::string( name ); } break; } case Toolkit::TextEditor::Property::SCROLL_THRESHOLD: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetScrollThreshold(); - } + value = impl.mDecorator->GetScrollThreshold(); break; } case Toolkit::TextEditor::Property::SCROLL_SPEED: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetScrollSpeed(); - } + value = impl.mDecorator->GetScrollSpeed(); break; } case Toolkit::TextEditor::Property::PRIMARY_CURSOR_COLOR: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetColor( PRIMARY_CURSOR ); - } + value = impl.mDecorator->GetColor( PRIMARY_CURSOR ); break; } case Toolkit::TextEditor::Property::SECONDARY_CURSOR_COLOR: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetColor( SECONDARY_CURSOR ); - } + value = impl.mDecorator->GetColor( SECONDARY_CURSOR ); break; } case Toolkit::TextEditor::Property::ENABLE_CURSOR_BLINK: @@ -895,42 +808,27 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::CURSOR_BLINK_INTERVAL: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetCursorBlinkInterval(); - } + value = impl.mDecorator->GetCursorBlinkInterval(); break; } case Toolkit::TextEditor::Property::CURSOR_BLINK_DURATION: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetCursorBlinkDuration(); - } + value = impl.mDecorator->GetCursorBlinkDuration(); break; } case Toolkit::TextEditor::Property::CURSOR_WIDTH: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetCursorWidth(); - } + value = impl.mDecorator->GetCursorWidth(); break; } case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ); - } + value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ); break; } case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ); - } + value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ); break; } case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT: @@ -965,44 +863,29 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::SELECTION_HIGHLIGHT_COLOR: { - if( impl.mDecorator ) - { - value = impl.mDecorator->GetHighlightColor(); - } + value = impl.mDecorator->GetHighlightColor(); break; } case Toolkit::TextEditor::Property::DECORATION_BOUNDING_BOX: { - if( impl.mDecorator ) - { - Rect boundingBox; - impl.mDecorator->GetBoundingBox( boundingBox ); - value = boundingBox; - } + Rect boundingBox; + impl.mDecorator->GetBoundingBox( boundingBox ); + value = boundingBox; break; } case Toolkit::TextEditor::Property::ENABLE_MARKUP: { - if( impl.mController ) - { - value = impl.mController->IsMarkupProcessorEnabled(); - } + value = impl.mController->IsMarkupProcessorEnabled(); break; } case Toolkit::TextEditor::Property::INPUT_COLOR: { - if( impl.mController ) - { - value = impl.mController->GetInputColor(); - } + value = impl.mController->GetInputColor(); break; } case Toolkit::TextEditor::Property::INPUT_FONT_FAMILY: { - if( impl.mController ) - { - value = impl.mController->GetInputFontFamily(); - } + value = impl.mController->GetInputFontFamily(); break; } case Toolkit::TextEditor::Property::INPUT_FONT_STYLE: @@ -1012,28 +895,19 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::INPUT_POINT_SIZE: { - if( impl.mController ) - { - value = impl.mController->GetInputFontPointSize(); - } + value = impl.mController->GetInputFontPointSize(); break; } case Toolkit::TextEditor::Property::LINE_SPACING: { - if( impl.mController ) - { - // LINE_SPACING isn't implemented for the TextEditor. Returning - // only shadowed value, not the real one. - value = impl.mLineSpacing; - } + // LINE_SPACING isn't implemented for the TextEditor. Returning + // only shadowed value, not the real one. + value = impl.mLineSpacing; break; } case Toolkit::TextEditor::Property::INPUT_LINE_SPACING: { - if( impl.mController ) - { - value = impl.mController->GetInputLineSpacing(); - } + value = impl.mController->GetInputLineSpacing(); break; } case Toolkit::TextEditor::Property::UNDERLINE: @@ -1103,45 +977,30 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::PIXEL_SIZE: { - if( impl.mController ) - { - value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ); - } + value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ); break; } case Toolkit::TextEditor::Property::LINE_COUNT: { - if( impl.mController ) - { - float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get(); - value = impl.mController->GetLineCount( width ); - } + float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get(); + value = impl.mController->GetLineCount( width ); break; } case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT: { - if( impl.mController ) - { - std::string text; - impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text ); - value = text; - } + std::string text; + impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text ); + value = text; break; } case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR: { - if( impl.mController ) - { - value = impl.mController->GetPlaceholderTextColor(); - } + value = impl.mController->GetPlaceholderTextColor(); break; } case Toolkit::TextEditor::Property::ENABLE_SELECTION: { - if( impl.mController ) - { - value = impl.mController->IsSelectionEnabled(); - } + value = impl.mController->IsSelectionEnabled(); break; } case Toolkit::TextEditor::Property::PLACEHOLDER: @@ -1153,42 +1012,49 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } case Toolkit::TextEditor::Property::LINE_WRAP_MODE: { - if( impl.mController ) - { - value = impl.mController->GetLineWrapMode(); - } + value = impl.mController->GetLineWrapMode(); break; } case Toolkit::DevelTextEditor::Property::ENABLE_SHIFT_SELECTION: { - if( impl.mController ) - { - value = impl.mController->IsShiftSelectionEnabled(); - } + value = impl.mController->IsShiftSelectionEnabled(); break; } case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE: { - if( impl.mController ) - { - value = impl.mController->IsGrabHandleEnabled(); - } + value = impl.mController->IsGrabHandleEnabled(); break; } case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - if( impl.mController ) - { - value = impl.mController->IsMatchSystemLanguageDirection(); - } + value = impl.mController->IsMatchSystemLanguageDirection(); break; } case Toolkit::DevelTextEditor::Property::MAX_LENGTH: { - if( impl.mController ) - { - value = impl.mController->GetMaximumNumberOfCharacters(); - } + value = impl.mController->GetMaximumNumberOfCharacters(); + break; + } + case Toolkit::DevelTextEditor::Property::SELECTED_TEXT: + { + value = impl.mController->GetSelectedText( ); + break; + } + case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_START: + { + Uint32Pair range = impl.GetTextSelectionRange(); + value = static_cast(range.first); + break; + } + case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_END: + { + Uint32Pair range = impl.GetTextSelectionRange(); + value = static_cast(range.second); + break; + } + case Toolkit::DevelTextEditor::Property::ENABLE_EDITING: + { + value = impl.IsEditable(); break; } } //switch @@ -1197,6 +1063,33 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind return value; } +void TextEditor::SelectWholeText() +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SelectWholeText(); + SetKeyInputFocus(); + } +} + +void TextEditor::SelectNone() +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SelectNone(); + } +} + +string TextEditor::GetSelectedText() const +{ + string selectedText = ""; + if( mController && mController->IsShowingRealText() ) + { + selectedText = mController->GetSelectedText( ); + } + return selectedText; +} + InputMethodContext TextEditor::GetInputMethodContext() { return mInputMethodContext; @@ -1207,6 +1100,11 @@ DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal( return mMaxLengthReachedSignal; } +Text::ControllerPtr TextEditor::getController() +{ + return mController; +} + bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -1258,7 +1156,7 @@ void TextEditor::OnInitialize() { Actor self = Self(); - mController = Text::Controller::New( this, this ); + mController = Text::Controller::New( this, this, this); mDecorator = Text::Decorator::New( *mController, *mController ); @@ -1291,10 +1189,10 @@ void TextEditor::OnInitialize() mController->SetLayoutDirection( layoutDirection ); // Forward input events to controller - EnableGestureDetection( static_cast( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) ); + EnableGestureDetection( static_cast( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) ); GetTapGestureDetector().SetMaximumTapsRequired( 2 ); - self.TouchSignal().Connect( this, &TextEditor::OnTouched ); + self.TouchedSignal().Connect( this, &TextEditor::OnTouched ); // Set BoundingBox to stage size if not already set. Rect boundingBox; @@ -1400,7 +1298,15 @@ void TextEditor::OnRelayout( const Vector2& size, RelayoutContainer& container ) Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) ); // Support Right-To-Left of padding - Dali::LayoutDirection::Type layoutDirection = static_cast( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + Dali::LayoutDirection::Type layoutDirection; + if( mController->IsMatchSystemLanguageDirection() ) + { + layoutDirection = static_cast( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + } + else + { + layoutDirection = static_cast( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + } if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) { std::swap( padding.start, padding.end ); @@ -1506,7 +1412,7 @@ void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType ) void TextEditor::OnKeyInputFocusGained() { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() ); - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged ); @@ -1560,44 +1466,46 @@ void TextEditor::OnKeyInputFocusLost() void TextEditor::OnTap( const TapGesture& gesture ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() ); - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.Activate(); } // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures Extents padding; padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); - mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top ); + const Vector2& localPoint = gesture.GetLocalPoint(); + mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top ); SetKeyInputFocus(); } void TextEditor::OnPan( const PanGesture& gesture ) { - mController->PanEvent( gesture.state, gesture.displacement ); + mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() ); } void TextEditor::OnLongPress( const LongPressGesture& gesture ) { - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.Activate(); } Extents padding; padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); - mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top ); + const Vector2& localPoint = gesture.GetLocalPoint(); + mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top ); SetKeyInputFocus(); } bool TextEditor::OnKeyEvent( const KeyEvent& event ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() ); - if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() ) + if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() ) { // Make sure ClearKeyInputFocus when only key is up - if( event.state == KeyEvent::Up ) + if( event.GetState() == KeyEvent::UP ) { ClearKeyInputFocus(); } @@ -1613,6 +1521,30 @@ void TextEditor::RequestTextRelayout() RelayoutRequest(); } +void TextEditor::TextInserted( unsigned int position, unsigned int length, const std::string &content ) +{ + if( Accessibility::IsUp() ) + { + Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content ); + } +} + +void TextEditor::TextDeleted( unsigned int position, unsigned int length, const std::string &content ) +{ + if( Accessibility::IsUp() ) + { + Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content ); + } +} + +void TextEditor::CaretMoved( unsigned int position ) +{ + if( Accessibility::IsUp() ) + { + Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position ); + } +} + void TextEditor::TextChanged() { Dali::Toolkit::TextEditor handle( GetOwner() ); @@ -1697,6 +1629,25 @@ void TextEditor::AddDecoration( Actor& actor, bool needsClipping ) } } +void TextEditor::SetTextSelectionRange(const uint32_t *start, const uint32_t *end) +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SetTextSelectionRange( start, end ); + SetKeyInputFocus(); + } +} + +Uint32Pair TextEditor::GetTextSelectionRange() const +{ + Uint32Pair range(0, 0); + if( mController && mController->IsShowingRealText() ) + { + range = mController->GetTextSelectionRange(); + } + return range; +} + void TextEditor::UpdateScrollBar() { using namespace Dali; @@ -1719,8 +1670,8 @@ void TextEditor::UpdateScrollBar() CustomActor self = Self(); if( !mScrollBar ) { - mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::Vertical ); - mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::Variable ); + mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::VERTICAL ); + mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::VARIABLE ); mScrollBar.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); mScrollBar.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); mScrollBar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); @@ -1894,6 +1845,20 @@ void TextEditor::ApplyScrollPosition() } } +bool TextEditor::IsEditable() const +{ + return mController->IsEditable(); +} + +void TextEditor::SetEditable( bool editable ) +{ + mController->SetEditable(editable); + if ( mInputMethodContext && !editable ) + { + mInputMethodContext.Deactivate(); + } +} + TextEditor::TextEditor() : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mAnimationPeriod( 0.0f, 0.0f ), @@ -1907,6 +1872,10 @@ TextEditor::TextEditor() mScrollBarEnabled( false ), mScrollStarted( false ) { + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new AccessibleImpl( actor, Dali::Accessibility::Role::ENTRY ) ); + } ); } TextEditor::~TextEditor() @@ -1920,6 +1889,212 @@ TextEditor::~TextEditor() } } +std::string TextEditor::AccessibleImpl::GetName() +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + return slf.GetProperty( Toolkit::TextEditor::Property::TEXT ) + .Get< std::string >(); +} + +std::string TextEditor::AccessibleImpl::GetText( size_t startOffset, + size_t endOffset ) +{ + if( endOffset <= startOffset ) + return {}; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = + slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + + if( startOffset > txt.size() || endOffset > txt.size() ) + return {}; + + return txt.substr( startOffset, endOffset - startOffset ); +} + +size_t TextEditor::AccessibleImpl::GetCharacterCount() +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = + slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + + return txt.size(); +} + +size_t TextEditor::AccessibleImpl::GetCaretOffset() +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition(); +} + +bool TextEditor::AccessibleImpl::SetCaretOffset(size_t offset) +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + if (offset > txt.size()) + return false; + + auto& slfImpl = Dali::Toolkit::GetImpl( slf ); + slfImpl.getController()->ResetCursorPosition( offset ); + slfImpl.RequestTextRelayout(); + return true; +} + +Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset( + size_t offset, Dali::Accessibility::TextBoundary boundary ) +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + auto txt_size = txt.size(); + + auto range = Dali::Accessibility::Range{}; + + switch(boundary) + { + case Dali::Accessibility::TextBoundary::CHARACTER: + { + if (offset < txt_size) + { + range.content = txt[offset]; + range.startOffset = offset; + range.endOffset = offset + 1; + } + } + break; + case Dali::Accessibility::TextBoundary::WORD: + case Dali::Accessibility::TextBoundary::LINE: + { + auto txt_c_string = txt.c_str(); + auto breaks = std::vector< char >( txt_size, 0 ); + if(boundary == Dali::Accessibility::TextBoundary::WORD) + Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data()); + else + Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data()); + auto index = 0u; + auto counter = 0u; + while( index < txt_size && counter <= offset ) + { + auto start = index; + if(breaks[index]) + { + while(breaks[index]) + index++; + counter++; + } + else + { + if (boundary == Dali::Accessibility::TextBoundary::WORD) + index++; + if (boundary == Dali::Accessibility::TextBoundary::LINE) + counter++; + } + if ((counter - 1) == offset) + { + range.content = txt.substr(start, index - start + 1); + range.startOffset = start; + range.endOffset = index + 1; + } + if (boundary == Dali::Accessibility::TextBoundary::LINE) + index++; + } + } + break; + case Dali::Accessibility::TextBoundary::SENTENCE: + { + /* not supported by efl */ + } + break; + case Dali::Accessibility::TextBoundary::PARAGRAPH: + { + /* Paragraph is not supported by libunibreak library */ + } + break; + default: + break; + } + + return range; +} + +Dali::Accessibility::Range +TextEditor::AccessibleImpl::GetSelection( size_t selectionNum ) +{ + // Since DALi supports only one selection indexes higher than 0 are ignored + if( selectionNum > 0 ) + return {}; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto ctrl = Dali::Toolkit::GetImpl( slf ).getController(); + std::string ret; + ctrl->RetrieveSelection( ret ); + auto r = ctrl->GetSelectionIndexes(); + + return { static_cast(r.first), static_cast(r.second), ret }; +} + +bool TextEditor::AccessibleImpl::RemoveSelection( size_t selectionNum ) +{ + // Since DALi supports only one selection indexes higher than 0 are ignored + if( selectionNum > 0 ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 ); + return true; +} + +bool TextEditor::AccessibleImpl::SetSelection( size_t selectionNum, + size_t startOffset, + size_t endOffset ) +{ + // Since DALi supports only one selection indexes higher than 0 are ignored + if( selectionNum > 0 ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset, + endOffset ); + return true; +} + +bool TextEditor::AccessibleImpl::CopyText( size_t startPosition, + size_t endPosition ) +{ + if( endPosition <= startPosition ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get(); + Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) ); + + return true; +} + +bool TextEditor::AccessibleImpl::CutText( size_t startPosition, + size_t endPosition ) +{ + if( endPosition <= startPosition ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get(); + Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) ); + + slf.SetProperty( Toolkit::TextEditor::Property::TEXT, + txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size())); + + return true; +} + +Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates() +{ + auto states = Control::Impl::AccessibleImpl::CalculateStates(); + using namespace Dali::Accessibility; + states[State::EDITABLE] = true; + + return states; +} + } // namespace Internal } // namespace Toolkit