/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <cstring>
#include <limits>
#include <dali/public-api/adaptor-framework/key.h>
-#include <dali/public-api/common/stage.h>
-#include <dali/public-api/images/resource-image.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/devel-api/common/stage.h>
#include <dali/devel-api/actors/actor-devel.h>
#include <dali/devel-api/object/property-helper-devel.h>
#include <dali/public-api/object/type-registry-helper.h>
-#include <dali/integration-api/adaptors/adaptor.h>
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/text/rendering-backend.h>
#include <dali-toolkit/public-api/text/text-enumerations.h>
#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/devel-api/text/rendering-backend.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
-#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/text/text-enumerations-impl.h>
#include <dali-toolkit/internal/text/rendering/text-backend.h>
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
#endif
-const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
+const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
} // unnamed namespace
// Setup properties, signals and actions using the type-registry.
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextEditor, Toolkit::Control, Create );
-DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND )
DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "text", STRING, TEXT )
DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "textColor", VECTOR4, TEXT_COLOR )
DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontFamily", STRING, FONT_FAMILY )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
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_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
+DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
DALI_TYPE_REGISTRATION_END()
+const char * const IMAGE_MAP_FILENAME_STRING = "filename";
+
+/// Retrieves a filename from a value that is a Property::Map
+std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
+{
+ std::string filename;
+ const Property::Map* map = value.GetMap();
+ if( map )
+ {
+ const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
+ if( filenameValue )
+ {
+ filenameValue->Get( filename );
+ }
+ }
+ return filename;
+}
+
} // namespace
Toolkit::TextEditor TextEditor::New()
switch( index )
{
- case Toolkit::TextEditor::Property::RENDERING_BACKEND:
+ case Toolkit::DevelTextEditor::Property::RENDERING_BACKEND:
{
int backend = value.Get< int >();
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
}
case Toolkit::TextEditor::Property::GRAB_HANDLE_IMAGE:
{
- const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
+ 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 )
+ if( impl.mDecorator && imageFileName.size() )
{
- impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
+ impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE:
{
- const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
+ 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 )
+ if( impl.mDecorator && imageFileName.size() )
{
- impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
+ impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT:
{
- const Image image = Scripting::NewImage( value );
+ const std::string filename = GetImageFileNameFromPropertyValue( value );
- if( impl.mDecorator && image )
+ if( impl.mDecorator && filename.size() )
{
- impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
+ impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT:
{
- const Image image = Scripting::NewImage( value );
+ const std::string filename = GetImageFileNameFromPropertyValue( value );
- if( impl.mDecorator && image )
+ if( impl.mDecorator && filename.size() )
{
- impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
+ impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
{
- const Image image = Scripting::NewImage( value );
+ const std::string filename = GetImageFileNameFromPropertyValue( value );
- if( impl.mDecorator && image )
+ if( impl.mDecorator && filename.size() )
{
- impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
+ impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
{
- const Image image = Scripting::NewImage( value );
+ const std::string filename = GetImageFileNameFromPropertyValue( value );
- if( impl.mDecorator && image )
+ if( impl.mDecorator && filename.size() )
{
- impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
+ impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
{
- const Image image = Scripting::NewImage( value );
+ const std::string filename = GetImageFileNameFromPropertyValue( value );
- if( impl.mDecorator && image )
+ if( impl.mDecorator && filename.size() )
{
- impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
+ impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
impl.RequestTextRelayout();
}
break;
}
case Toolkit::TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
{
- const Image image = Scripting::NewImage( value );
+ const std::string filename = GetImageFileNameFromPropertyValue( value );
- if( impl.mDecorator && image )
+ if( impl.mDecorator && filename.size() )
{
- impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
+ impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
impl.RequestTextRelayout();
}
break;
if( impl.mController )
{
- // The line spacing isn't supported by the TextEditor. Since it's
- // supported by the TextEditor for now it must be ignored. The
- // property is being shadowed locally so its value isn't affected.
+ // 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<float>();
impl.mLineSpacing = lineSpacing;
// set it to 0.0 due to missing implementation
}
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 );
+
+ impl.mController->SetMaximumNumberOfCharacters( max );
+ }
+ break;
+ }
} // switch
} // texteditor
}
switch( index )
{
- case Toolkit::TextEditor::Property::RENDERING_BACKEND:
+ case Toolkit::DevelTextEditor::Property::RENDERING_BACKEND:
{
value = impl.mRenderingBackend;
break;
{
if( impl.mDecorator )
{
- ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
- if( image )
- {
- value = image.GetUrl();
- }
+ value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
}
break;
}
{
if( impl.mDecorator )
{
- ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
- if( image )
- {
- value = image.GetUrl();
- }
+ value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
}
break;
}
}
break;
}
+ case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
+ {
+ if( impl.mController )
+ {
+ value = impl.mController->GetMaximumNumberOfCharacters();
+ }
+ break;
+ }
} //switch
}
return mInputMethodContext;
}
-Text::ControllerPtr TextEditor::getController()
+DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
{
- return mController;
+ return mMaxLengthReachedSignal;
}
bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
{
editor.InputStyleChangedSignal().Connect( tracker, functor );
}
+ else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
+ {
+ if( editor )
+ {
+ Internal::TextEditor& editorImpl( GetImpl( editor ) );
+ editorImpl.MaxLengthReachedSignal().Connect( tracker, functor );
+ }
+ }
else
{
// signalName does not match any signal
// Fill-parent area by default
self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
- self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
+ self.OnSceneSignal().Connect( this, &TextEditor::OnSceneConnect );
DevelControl::SetInputMethodContext( *this, mInputMethodContext );
// Creates an extra control to be used as stencil buffer.
mStencil = Control::New();
- mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
// Creates a background visual. Even if the color is transparent it updates the stencil.
mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
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<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+ Dali::LayoutDirection::Type layoutDirection;
+ if( mController->IsMatchSystemLanguageDirection() )
+ {
+ layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+ }
+ else
+ {
+ layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+ }
if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
{
std::swap( padding.start, padding.end );
if( mStencil )
{
- mStencil.SetPosition( padding.start, padding.top );
+ mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
}
if( mActiveLayer )
{
- mActiveLayer.SetPosition( padding.start, padding.top );
+ mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
}
const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
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() );
void TextEditor::MaxLengthReached()
{
- // Nothing to do as TextEditor doesn't emit a max length reached signal.
+ Dali::Toolkit::TextEditor handle( GetOwner() );
+ mMaxLengthReachedSignal.Emit( handle );
}
void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
}
else
{
- actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
- actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
Self().Add( actor );
mActiveLayer = actor;
}
{
mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::Vertical );
mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::Variable );
- mScrollBar.SetParentOrigin( ParentOrigin::TOP_RIGHT );
- mScrollBar.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
+ 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 );
mScrollBar.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
{
mAnimation = Animation::New( mAnimationPeriod.durationSeconds );
}
- indicator.SetOpacity(1.0f);
+ indicator.SetProperty( Actor::Property::OPACITY,1.0f);
mAnimation.AnimateTo( Property( indicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod );
mAnimation.Play();
mAnimation.FinishedSignal().Connect( this, &TextEditor::OnScrollIndicatorAnimationFinished );
}
}
-void TextEditor::OnStageConnect( Dali::Actor actor )
+void TextEditor::OnSceneConnect( Dali::Actor actor )
{
if ( mHasBeenStaged )
{
{
if( mDecorator )
{
- ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
-
- if ( image )
- {
- Property::Map map;
- Scripting::CreatePropertyMap( image, map );
- value = map;
- }
+ Property::Map map;
+ map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
+ value = map;
}
}
}
}
-void TextEditor::OnStageConnection( int depth )
+void TextEditor::OnSceneConnection( int depth )
{
// Sets the depth to the visuals inside the text's decorator.
mDecorator->SetTextDepth( depth );
// The depth of the text renderer is set in the RenderText() called from OnRelayout().
- // Call the Control::OnStageConnection() to set the depth of the background.
- Control::OnStageConnection( depth );
+ // Call the Control::OnSceneConnection() to set the depth of the background.
+ Control::OnSceneConnection( depth );
}
-bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
+bool TextEditor::OnTouched( Actor actor, const TouchEvent& touch )
{
return true;
}
}
else if ( Equals( scrollAmount, 0.0f, Math::MACHINE_EPSILON_1 ))
{
- mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount );
+ mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount ));
}
else
{
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()
}
}
-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<size_t>(r.first), static_cast<size_t>(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<std::string>();
- 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<std::string>();
- 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