END_TEST;
}
+
+int UtcDaliTextEditorPrimaryCursorPosition(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextPrimaryCursorPosition ");
+
+ TextEditor textEditor = TextEditor::New();
+
+ application.GetScene().Add( textEditor );
+
+ textEditor.SetProperty( TextEditor::Property::TEXT, "ABCEF");
+ textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
+ textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ textEditor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3);
+ application.SendNotification();
+ application.Render();
+
+ application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get<std::string>(), "ABCDEF", TEST_LOCATION );
+ DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 4, TEST_LOCATION );
+
+ END_TEST;
+}
END_TEST;
}
+
+int UtcDaliTextFieldPrimaryCursorPosition(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextFieldPrimaryCursorPosition ");
+
+ TextField textField = TextField::New();
+
+ application.GetScene().Add( textField );
+
+ textField.SetProperty( TextField::Property::TEXT, "ABCEF");
+ textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
+ textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ textField.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
+ application.SendNotification();
+ application.Render();
+
+ application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "ABCDEF", TEST_LOCATION );
+ DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 4, TEST_LOCATION );
+
+ END_TEST;
+}
* - fontSize: 10pt, fontSizeScale: 1.5
*/
FONT_SIZE_SCALE,
+
+ /**
+ * @brief The position for primary cursor.
+ * @details Name "primaryCursorPosition", type Property::INTEGER.
+ */
+ PRIMARY_CURSOR_POSITION,
};
} // namespace Property
* - fontSize: 15pt, fontSizeScale: 1.0
* - fontSize: 10pt, fontSizeScale: 1.5
*/
- FONT_SIZE_SCALE
+ FONT_SIZE_SCALE,
+
+ /**
+ * @brief The position for primary cursor.
+ * @details Name "primaryCursorPosition", type Property::INTEGER.
+ */
+ PRIMARY_CURSOR_POSITION,
};
} // namespace Property
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING )
DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED )
DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
}
break;
}
+ case Toolkit::DevelTextEditor::Property::PRIMARY_CURSOR_POSITION:
+ {
+ uint32_t position = static_cast<uint32_t>(value.Get< int >());
+ DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position );
+ if (impl.mController->SetPrimaryCursorPosition( position ))
+ {
+ impl.SetKeyInputFocus();
+ }
+ break;
+ }
} // switch
} // texteditor
}
value = impl.mController->GetFontSizeScale();
break;
}
+ case Toolkit::DevelTextEditor::Property::PRIMARY_CURSOR_POSITION:
+ {
+ value = static_cast<int>(impl.mController->GetPrimaryCursorPosition());
+ break;
+ }
} //switch
}
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "fontSizeScale", FLOAT, FONT_SIZE_SCALE )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION )
DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
}
break;
}
+ case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
+ {
+ uint32_t position = static_cast<uint32_t>(value.Get< int >());
+ DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position );
+ if (impl.mController->SetPrimaryCursorPosition( position ))
+ {
+ impl.SetKeyInputFocus();
+ }
+ break;
+ }
} // switch
} // textfield
}
value = impl.mController->GetFontSizeScale();
break;
}
+ case Toolkit::DevelTextField::Property::PRIMARY_CURSOR_POSITION:
+ {
+ value = static_cast<int>(impl.mController->GetPrimaryCursorPosition());
+ break;
+ }
} //switch
}
}
}
+CharacterIndex Controller::Impl::GetPrimaryCursorPosition() const
+{
+ if( nullptr == mEventData )
+ {
+ return 0;
+ }
+ return mEventData->mPrimaryCursorPosition;
+}
+
+bool Controller::Impl::SetPrimaryCursorPosition( CharacterIndex index )
+{
+ if( nullptr == mEventData )
+ {
+ // Nothing to do if there is no text.
+ return false;
+ }
+
+ if( mEventData->mPrimaryCursorPosition == index )
+ {
+ // Nothing for same cursor position.
+ return false;
+ }
+
+ uint32_t length = static_cast<uint32_t>(mModel->mLogicalModel->mText.Count());
+ mEventData->mPrimaryCursorPosition = std::min(index, length);
+ ChangeState( EventData::EDITING );
+ mEventData->mLeftSelectionPosition = mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
+ mEventData->mUpdateCursorPosition = true;
+ ScrollTextToMatchCursor();
+ return true;
+}
+
Uint32Pair Controller::Impl::GetTextSelectionRange() const
{
Uint32Pair range;
ScrollToMakePositionVisible( cursorInfo.primaryPosition, cursorInfo.lineHeight );
}
+void Controller::Impl::ScrollTextToMatchCursor()
+{
+ CursorInfo cursorInfo;
+ GetCursorPosition( mEventData->mPrimaryCursorPosition, cursorInfo );
+ ScrollTextToMatchCursor(cursorInfo);
+}
+
void Controller::Impl::RequestRelayout()
{
if( NULL != mControlInterface )
void OnSelectNoneEvent();
+ /**
+ * @copydoc Text::Controller::GetPrimaryCursorPosition()
+ */
+ CharacterIndex GetPrimaryCursorPosition() const;
+
+ /**
+ * @copydoc Text::Controller::SetPrimaryCursorPosition()
+ */
+ bool SetPrimaryCursorPosition( CharacterIndex index );
+
/**
* @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
*/
*/
void ScrollTextToMatchCursor( const CursorInfo& cursorInfo );
+ /**
+ * @brief Scrolls the text to make primary cursor visible.
+ */
+ void ScrollTextToMatchCursor( );
+
/**
* @brief Create an actor that renders the text background color
*
return mImpl->GetTextSelectionRange();
}
+CharacterIndex Controller::GetPrimaryCursorPosition() const
+{
+ return mImpl->GetPrimaryCursorPosition();
+}
+
+bool Controller::SetPrimaryCursorPosition( CharacterIndex index )
+{
+ if( mImpl->mEventData )
+ {
+ mImpl->mEventData->mCheckScrollAmount = true;
+ mImpl->mEventData->mIsLeftHandleSelected = true;
+ mImpl->mEventData->mIsRightHandleSelected = true;
+ mImpl->mEventData->mCheckScrollAmount = true;
+ if( mImpl->SetPrimaryCursorPosition(index) )
+ {
+ KeyboardFocusGainEvent();
+ return true;
+ }
+ }
+ return false;
+}
+
void Controller::SelectWholeText()
{
SelectEvent( 0.f, 0.f, SelectionType::ALL );
*/
void LongPressEvent( GestureState state, float x, float y );
+ /**
+ * @brief Used to get the Primary cursor position.
+ *
+ * @return Primary cursor position.
+ */
+ CharacterIndex GetPrimaryCursorPosition() const;
+
+ /**
+ * @brief Used to set the Primary cursor position.
+ *
+ * @param[in] index for the Primary cursor position.
+ * @return[in] true if cursor position changed, false otherwise.
+ */
+ bool SetPrimaryCursorPosition( CharacterIndex index );
+
/**
* @brief Creates a selection event.
*