controller->SetText( text );
// Select the whole text.
- controller->SelectEvent( 0.f, 0.f, false );
+ controller->SelectEvent( 0.f, 0.f, SelectionType::INTERACTIVE );
// Perform a relayout
const Size size( Dali::Stage::GetCurrent().GetSize() );
DALI_TEST_EQUALS( "Hello", retrieved_text, TEST_LOCATION );
// Select the whole text.
- controller->SelectEvent( 0.f, 0.f, true );
+ controller->SelectEvent( 0.f, 0.f, SelectionType::ALL );
// Perform a relayout
controller->Relayout( size );
END_TEST;
}
+
+int UtcDaliTextFieldSelectNone(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextFieldSelectWholeText ");
+
+ TextField textField = TextField::New();
+
+ Stage::GetCurrent().Add( textField );
+
+ textField.SetSize( 300.f, 50.f );
+ textField.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ textField.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ application.SendNotification();
+ application.Render();
+
+ textField.SetProperty( TextField::Property::TEXT, "Hello world" );
+
+ application.SendNotification();
+ application.Render();
+
+ // Nothing is selected
+ std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+ DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
+
+ DevelTextField::SelectWholeText( textField );
+
+ application.SendNotification();
+ application.Render();
+
+ // whole text is selected
+ selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+ DALI_TEST_EQUALS( "Hello world", selectedText, TEST_LOCATION );
+
+ DevelTextField::SelectNone( textField );
+
+ application.SendNotification();
+ application.Render();
+
+ // Nothing is selected
+ selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+ DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
+
+ END_TEST;
+}
GetImpl( textField ).SelectWholeText();
}
+void SelectNone( TextField textField )
+{
+ GetImpl( textField ).SelectNone();
+}
+
} // namespace DevelText
} // namespace Toolkit
* @note Use "textBackground" as property name to avoid conflict with Control's "background" property.
* @note The default value is Color::TRANSPARENT.
*/
- BACKGROUND = ELLIPSIS + 5
+ BACKGROUND = ELLIPSIS + 5,
+
+
+ /**
+ * @brief The selected text in UTF-8 format.
+ * @details Name "selectedText", type Property::STRING.
+ * @note This property is read-only.
+ */
+ SELECTED_TEXT = ELLIPSIS + 6
};
} // namespace Property
* @brief Select the whole text of TextField.
*
* @param[in] textField The instance of TextField.
- * @return InputMethodContext instance.
*/
DALI_TOOLKIT_API void SelectWholeText( TextField textField );
+/**
+ * @brief Unselect the whole text of TextField.
+ *
+ * @param[in] textField The instance of TextField.
+ */
+DALI_TOOLKIT_API void SelectNone( TextField textField );
+
+/**
+ * @brief Get the selected text of TextField.
+ *
+ * @param[in] textField The instance of TextField.
+ * @return Selected text in the TextField.
+ */
+DALI_TOOLKIT_API std::string SelectedText( TextField textField );
+
} // namespace DevelText
} // namespace Toolkit
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
+DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
}
break;
}
+ case Toolkit::DevelTextField::Property::SELECTED_TEXT:
+ {
+ if( impl.mController )
+ {
+ value = impl.mController->GetSelectedText( );
+ }
+ break;
+ }
} //switch
}
{
if( mController && mController->IsShowingRealText() )
{
- mController->SelectEvent( 0.f, 0.f, true );
+ mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
+ SetKeyInputFocus();
+ }
+}
+
+void TextField::SelectNone()
+{
+ if( mController && mController->IsShowingRealText() )
+ {
+ mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
SetKeyInputFocus();
}
}
*/
void SelectWholeText();
+ /**
+ * @brief Called to unselect the whole texts.
+ */
+ void SelectNone();
+
+ /**
+ * @brief Called to get selected text.
+ * @return Selected text in the TextField.
+ */
+ std::string SelectedText();
+
private: // From Control
/**
OnSelectAllEvent();
break;
}
+ case Event::SELECT_NONE:
+ {
+ OnSelectNoneEvent();
+ break;
+ }
}
}
}
}
}
+void Controller::Impl::OnSelectNoneEvent()
+{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "OnSelectNoneEvent mEventData->mSelectionEnabled%s \n", mEventData->mSelectionEnabled?"true":"false");
+
+ if( NULL == mEventData )
+ {
+ // Nothing to do if there is no text.
+ return;
+ }
+
+ if( mEventData->mSelectionEnabled && mEventData->mState == EventData::SELECTING)
+ {
+ mEventData->mPrimaryCursorPosition = 0u;
+ mEventData->mLeftSelectionPosition = mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
+ ChangeState( EventData::INACTIVE );
+ mEventData->mUpdateCursorPosition = true;
+ mEventData->mUpdateInputStyle = true;
+ mEventData->mScrollAfterUpdatePosition = true;
+ }
+}
+
void Controller::Impl::RetrieveSelection( std::string& selectedText, bool deleteAfterRetrieval )
{
if( mEventData->mLeftSelectionPosition == mEventData->mRightSelectionPosition )
LEFT_SELECTION_HANDLE_EVENT,
RIGHT_SELECTION_HANDLE_EVENT,
SELECT,
- SELECT_ALL
+ SELECT_ALL,
+ SELECT_NONE,
};
union Param
void OnSelectAllEvent();
+ void OnSelectNoneEvent();
+
/**
* @brief Retrieves the selected text. It removes the text if the @p deleteAfterRetrieval parameter is @e true.
*
}
}
-void Controller::SelectEvent( float x, float y, bool selectAll )
+void Controller::SelectEvent( float x, float y, SelectionType selectType )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
if( NULL != mImpl->mEventData )
{
- if( selectAll )
+ if( selectType == SelectionType::ALL )
{
Event event( Event::SELECT_ALL );
mImpl->mEventData->mEventQueue.push_back( event );
}
+ else if( selectType == SelectionType::NONE )
+ {
+ Event event( Event::SELECT_NONE );
+ mImpl->mEventData->mEventQueue.push_back( event );
+ }
else
{
Event event( Event::SELECT );
if( mImpl->mEventData->mSelectionEnabled )
{
// Creates a SELECT event.
- SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
+ SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
}
break;
}
case Toolkit::TextSelectionPopup::SELECT_ALL:
{
// Creates a SELECT_ALL event
- SelectEvent( 0.f, 0.f, true );
+ SelectEvent( 0.f, 0.f, SelectionType::ALL );
break;
}
case Toolkit::TextSelectionPopup::CLIPBOARD:
return textRemoved;
}
+std::string Controller::GetSelectedText()
+{
+ std::string text;
+ if( EventData::SELECTING == mImpl->mEventData->mState )
+ {
+ mImpl->RetrieveSelection( text, false );
+ }
+ return text;
+}
+
// private : Relayout.
bool Controller::DoRelayout( const Size& size,
class View;
class RenderingController;
+ /**
+ * @brief Text selection operations .
+ */
+ enum SelectionType
+ {
+ INTERACTIVE = 0x0000,
+ ALL = 0x0001,
+ NONE = 0x0002
+ };
+
typedef IntrusivePtr<Controller> ControllerPtr;
/**
*
* @param[in] x The x position relative to the top-left of the parent control.
* @param[in] y The y position relative to the top-left of the parent control.
- * @param[in] selectAll Whether the whole text is selected.
+ * @param[in] selection type like the whole text is selected or unselected.
*/
- void SelectEvent( float x, float y, bool selectAll );
+ void SelectEvent( float x, float y, SelectionType selection );
/**
* @brief Event received from input method context
*/
Actor CreateBackgroundActor();
+ /**
+ * @brief Retrive Selected text.
+ *
+ * @return The seleced text.
+ */
+ std::string GetSelectedText();
+
protected: // Inherit from Text::Decorator::ControllerInterface.
/**
* @SINCE_1_2.60
* @note PLACEHOLDER map is used to add ellipsis to placeholder text.
*/
- ELLIPSIS,
+ ELLIPSIS
};
};