mUpdateLeftSelectionPosition( false ),
mUpdateRightSelectionPosition( false ),
mScrollAfterUpdatePosition( false ),
- mScrollAfterDelete( false )
+ mScrollAfterDelete( false ),
+ mAllTextSelected( false )
{}
EventData::~EventData()
OnTapEvent( *iter );
break;
}
+ case Event::LONG_PRESS_EVENT:
+ {
+ OnLongPressEvent( *iter );
+ break;
+ }
case Event::PAN_EVENT:
{
OnPanEvent( *iter );
leftScroll = true;
}
+ SetPopupButtons();
mEventData->mDecoratorUpdated = true;
mEventData->mUpdateLeftSelectionPosition = false;
}
rightScroll = true;
}
+ SetPopupButtons();
mEventData->mDecoratorUpdated = true;
mEventData->mUpdateRightSelectionPosition = false;
}
}
}
+void Controller::Impl::OnLongPressEvent( const Event& event )
+{
+ if ( EventData::EDITING == mEventData->mState )
+ {
+ ChangeState ( EventData::EDITING_WITH_POPUP );
+ mEventData->mDecoratorUpdated = true;
+ }
+}
+
void Controller::Impl::OnHandleEvent( const Event& event )
{
if( NULL == mEventData )
}
}
+void Controller::Impl::ShowClipboard()
+{
+ if ( mClipboard )
+ {
+ mClipboard.ShowClipboard();
+ }
+}
+
+void Controller::Impl::HideClipboard()
+{
+ if ( mClipboard )
+ {
+ mClipboard.HideClipboard();
+ }
+}
+
bool Controller::Impl::CopyStringToClipboard( std::string& source )
{
//Send string to clipboard
RepositionSelectionHandles( selectionStart, selectionEnd );
}
+void Controller::Impl::SetPopupButtons()
+{
+ /**
+ * Sets the Popup buttons to be shown depending on State.
+ *
+ * If SELECTING : CUT & COPY + ( PASTE & CLIPBOARD if content available to paste )
+ *
+ * If EDITING_WITH_POPUP : SELECT & SELECT_ALL
+ */
+
+ TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::NONE;
+
+ if ( ( EventData::SELECTING == mEventData->mState ) || ( EventData::SELECTION_CHANGED == mEventData->mState ) )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY );
+
+ if ( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) );
+ }
+
+ if ( !mEventData->mAllTextSelected )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::SELECT_ALL ) );
+ }
+ }
+ else if ( EventData::EDITING_WITH_POPUP == mEventData->mState )
+ {
+ if ( mLogicalModel->mText.Count() && !IsShowingPlaceholderText())
+ {
+ buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL );
+ }
+
+ if ( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) );
+ }
+ }
+
+ mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
+}
+
void Controller::Impl::ChangeState( EventData::State newState )
{
if( NULL == mEventData )
mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
mEventData->mDecorator->SetPopupActive( false );
mEventData->mDecoratorUpdated = true;
+ HideClipboard();
}
else if ( EventData::SELECTING == mEventData->mState )
{
mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true );
if( mEventData->mGrabHandlePopupEnabled )
{
- TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY );
- if ( !IsClipboardEmpty() )
- {
- buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
- }
-
- mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
+ SetPopupButtons();
mEventData->mDecorator->SetPopupActive( true );
}
mEventData->mDecoratorUpdated = true;
{
if( mEventData->mGrabHandlePopupEnabled )
{
- TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY );
- if ( !IsClipboardEmpty() )
- {
- buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
- }
+ SetPopupButtons();
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
- mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
mEventData->mDecorator->SetPopupActive( true );
}
mEventData->mDecoratorUpdated = true;
mEventData->mDecorator->SetPopupActive( false );
}
mEventData->mDecoratorUpdated = true;
+ HideClipboard();
}
else if( EventData::EDITING_WITH_POPUP == mEventData->mState )
{
}
if( mEventData->mGrabHandlePopupEnabled )
{
- TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL );
-
- if ( !IsClipboardEmpty() )
- {
- buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
- }
-
- mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
+ SetPopupButtons();
mEventData->mDecorator->SetPopupActive( true );
}
+ HideClipboard();
mEventData->mDecoratorUpdated = true;
}
else if ( EventData::SELECTION_HANDLE_PANNING == mEventData->mState )
// Get the glyphs per character table.
const Length* const glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin();
+ const Length* const charactersPerGlyphBuffer = mVisualModel->mCharactersPerGlyph.Begin();
// If the vector is void, there is no right to left characters.
const bool hasRightToLeftCharacters = NULL != visualToLogicalBuffer;
// The character in logical order.
const CharacterIndex characterLogicalOrderIndex = hasRightToLeftCharacters ? *( visualToLogicalBuffer + visualIndex ) : visualIndex;
+ // Get the script of the character.
+ const Script script = mLogicalModel->GetScript( characterLogicalOrderIndex );
+
// The first glyph for that character in logical order.
const GlyphIndex glyphLogicalOrderIndex = *( charactersToGlyphBuffer + characterLogicalOrderIndex );
-
// The number of glyphs for that character
const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterLogicalOrderIndex );
const Vector2& position = *( positionsBuffer + glyphLogicalOrderIndex );
- // Find the mid-point of the area containing the glyph
- const float glyphCenter = -glyphMetrics.xBearing + position.x + 0.5f * glyphMetrics.advance;
+ // Prevents to jump the whole Latin ligatures like fi, ff, ...
+ const Length numberOfCharactersInLigature = ( TextAbstraction::LATIN == script ) ? *( charactersPerGlyphBuffer + glyphLogicalOrderIndex ) : 1u;
+ const float glyphAdvance = glyphMetrics.advance / static_cast<float>( numberOfCharactersInLigature );
+
+ for( GlyphIndex index = 0u; !matched && ( index < numberOfCharactersInLigature ); ++index )
+ {
+ // Find the mid-point of the area containing the glyph
+ const float glyphCenter = -glyphMetrics.xBearing + position.x + ( static_cast<float>( index ) + 0.5f ) * glyphAdvance;
+
+ if( visualX < glyphCenter )
+ {
+ visualIndex += index;
+ matched = true;
+ break;
+ }
+ }
- if( visualX < glyphCenter )
+ if( matched )
{
- matched = true;
break;
}
}
logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex;
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex );
+
return logicalIndex;
}
cursorInfo.lineHeight = fontMetrics.ascender - fontMetrics.descender;
cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
- cursorInfo.primaryPosition.x = 0.f;
+ cursorInfo.primaryPosition.x = 1.f;
cursorInfo.primaryPosition.y = 0.f;
// Nothing else to do.
cursorPosition.x,
cursorPosition.y,
cursorInfo.lineHeight );
+
+ // If selection handle at start of the text and other at end of the text then all text is selected.
+ const CharacterIndex startOfSelection = std::min( mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition );
+ const CharacterIndex endOfSelection = std::max ( mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition );
+ mEventData->mAllTextSelected = ( startOfSelection == 0 ) && ( endOfSelection == mLogicalModel->mText.Count() );
}
void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
mEventData->mScrollPosition.x = currentCursorPosition.x - cursorInfo.primaryPosition.x - mAlignmentOffset.x;
ClampHorizontalScroll( mVisualModel->GetActualSize() );
- bool updateCursorPosition = true;
const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
- if( updateCursorPosition )
- {
- // Sets the cursor position.
- mEventData->mDecorator->SetPosition( PRIMARY_CURSOR,
- cursorPosition.x,
- cursorPosition.y,
- cursorInfo.primaryCursorHeight,
- cursorInfo.lineHeight );
+ // Sets the cursor position.
+ mEventData->mDecorator->SetPosition( PRIMARY_CURSOR,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.primaryCursorHeight,
+ cursorInfo.lineHeight );
- // Sets the grab handle position.
- mEventData->mDecorator->SetPosition( GRAB_HANDLE,
- cursorPosition.x,
- cursorPosition.y,
+ // Sets the grab handle position.
+ mEventData->mDecorator->SetPosition( GRAB_HANDLE,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.lineHeight );
+
+ if( cursorInfo.isSecondaryCursor )
+ {
+ mEventData->mDecorator->SetPosition( SECONDARY_CURSOR,
+ cursorInfo.secondaryPosition.x + offset.x,
+ cursorInfo.secondaryPosition.y + offset.y,
+ cursorInfo.secondaryCursorHeight,
cursorInfo.lineHeight );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y );
+ }
+ // Set which cursors are active according the state.
+ if( ( EventData::EDITING == mEventData->mState ) ||
+ ( EventData::EDITING_WITH_POPUP == mEventData->mState ) ||
+ ( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) )
+ {
if( cursorInfo.isSecondaryCursor )
{
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_BOTH );
- mEventData->mDecorator->SetPosition( SECONDARY_CURSOR,
- cursorInfo.secondaryPosition.x + offset.x,
- cursorInfo.secondaryPosition.y + offset.y,
- cursorInfo.secondaryCursorHeight,
- cursorInfo.lineHeight );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y );
}
else
{
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
}
}
+ else
+ {
+ mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
+ }
}
void Controller::Impl::RequestRelayout()