mScrollPosition(),
mState( INACTIVE ),
mPrimaryCursorPosition( 0u ),
- mSecondaryCursorPosition( 0u ),
+ mLeftSelectionPosition( 0u ),
+ mRightSelectionPosition( 0u ),
mDecoratorUpdated( false ),
mCursorBlinkEnabled( true ),
mGrabHandleEnabled( true ),
- mGrabHandlePopupEnabled( true ),
- mSelectionEnabled( true ),
+ mGrabHandlePopupEnabled( false ),
+ mSelectionEnabled( false ),
mHorizontalScrollingEnabled( true ),
mVerticalScrollingEnabled( false ),
mUpdateCursorPosition( false ),
+ mUpdateLeftSelectionPosition( false ),
+ mUpdateRightSelectionPosition( false ),
mScrollAfterUpdateCursorPosition( false )
{}
break;
}
case Event::GRAB_HANDLE_EVENT:
+ case Event::LEFT_SELECTION_HANDLE_EVENT:
+ case Event::RIGHT_SELECTION_HANDLE_EVENT: // Fall through
{
- OnGrabHandleEvent( *iter );
+ OnHandleEvent( *iter );
break;
}
}
mEventData->mScrollAfterUpdateCursorPosition = false;
}
+ mEventData->mDecoratorUpdated = true;
mEventData->mUpdateCursorPosition = false;
}
+ else if( mEventData->mUpdateLeftSelectionPosition )
+ {
+ UpdateSelectionHandle( LEFT_SELECTION_HANDLE );
+
+ if( mEventData->mScrollAfterUpdateCursorPosition )
+ {
+ ScrollToMakeCursorVisible();
+ mEventData->mScrollAfterUpdateCursorPosition = false;
+ }
+
+ mEventData->mDecoratorUpdated = true;
+ mEventData->mUpdateLeftSelectionPosition = false;
+ }
+ else if( mEventData->mUpdateRightSelectionPosition )
+ {
+ UpdateSelectionHandle( RIGHT_SELECTION_HANDLE );
+
+ if( mEventData->mScrollAfterUpdateCursorPosition )
+ {
+ ScrollToMakeCursorVisible();
+ mEventData->mScrollAfterUpdateCursorPosition = false;
+ }
+
+ mEventData->mDecoratorUpdated = true;
+ mEventData->mUpdateRightSelectionPosition = false;
+ }
mEventData->mEventQueue.clear();
}
}
-void Controller::Impl::OnGrabHandleEvent( const Event& event )
+void Controller::Impl::OnHandleEvent( const Event& event )
{
if( NULL == mEventData )
{
return;
}
- unsigned int state = event.p1.mUint;
+ const unsigned int state = event.p1.mUint;
- if( GRAB_HANDLE_PRESSED == state )
+ if( HANDLE_PRESSED == state )
{
// The event.p2 and event.p3 are in decorator coords. Need to transforms to text coords.
const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
- //mDecorator->HidePopup();
- ChangeState ( EventData::EDITING );
+ const CharacterIndex handleNewPosition = GetClosestCursorIndex( xPosition, yPosition );
- const CharacterIndex newCursorPosition = GetClosestCursorIndex( xPosition, yPosition );
+ if( Event::GRAB_HANDLE_EVENT == event.type )
+ {
+ ChangeState ( EventData::EDITING );
- if( newCursorPosition != mEventData->mPrimaryCursorPosition )
+ if( handleNewPosition != mEventData->mPrimaryCursorPosition )
+ {
+ mEventData->mPrimaryCursorPosition = handleNewPosition;
+ mEventData->mUpdateCursorPosition = true;
+ }
+ }
+ else if( Event::LEFT_SELECTION_HANDLE_EVENT == event.type )
{
- mEventData->mPrimaryCursorPosition = newCursorPosition;
- mEventData->mUpdateCursorPosition = true;
+ if( handleNewPosition != mEventData->mLeftSelectionPosition )
+ {
+ mEventData->mLeftSelectionPosition = handleNewPosition;
+ mEventData->mUpdateLeftSelectionPosition = true;
+ }
+ }
+ else if( Event::RIGHT_SELECTION_HANDLE_EVENT == event.type )
+ {
+ if( handleNewPosition != mEventData->mRightSelectionPosition )
+ {
+ mEventData->mRightSelectionPosition = handleNewPosition;
+ mEventData->mUpdateRightSelectionPosition = true;
+ }
}
}
- else if( mEventData->mGrabHandlePopupEnabled &&
- ( ( GRAB_HANDLE_RELEASED == state ) ||
- ( GRAB_HANDLE_STOP_SCROLLING == state ) ) )
+ else if( ( HANDLE_RELEASED == state ) ||
+ ( HANDLE_STOP_SCROLLING == state ) )
{
- //mDecorator->ShowPopup();
- ChangeState ( EventData::EDITING_WITH_POPUP );
- mEventData->mUpdateCursorPosition = true;
- mEventData->mDecoratorUpdated = true;
-
- if( GRAB_HANDLE_STOP_SCROLLING == state )
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ ChangeState( EventData::EDITING_WITH_POPUP );
+ }
+ if( Event::GRAB_HANDLE_EVENT == event.type )
{
- // The event.p2 and event.p3 are in decorator coords. Need to transforms to text coords.
- const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
- const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
+ mEventData->mUpdateCursorPosition = true;
+
+ if( HANDLE_STOP_SCROLLING == state )
+ {
+ // The event.p2 and event.p3 are in decorator coords. Need to transforms to text coords.
+ const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
+ const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
- mEventData->mPrimaryCursorPosition = GetClosestCursorIndex( xPosition, yPosition );
+ mEventData->mPrimaryCursorPosition = GetClosestCursorIndex( xPosition, yPosition );
- mEventData->mScrollAfterUpdateCursorPosition = true;
+ mEventData->mScrollAfterUpdateCursorPosition = true;
+ }
}
+ mEventData->mDecoratorUpdated = true;
}
- else if( GRAB_HANDLE_SCROLLING == state )
+ else if( HANDLE_SCROLLING == state )
{
const float xSpeed = event.p2.mFloat;
const Vector2& actualSize = mVisualModel->GetActualSize();
mEventData->mScrollPosition.x += xSpeed;
ClampHorizontalScroll( actualSize );
+
+ mEventData->mDecoratorUpdated = true;
}
}
const Vector<LineRun>& lines = mVisualModel->mLines;
float height = lines.Count() ? lines[0].ascender + -lines[0].descender : 0.0f;
- mEventData->mDecorator->SetPosition( PRIMARY_SELECTION_HANDLE, primaryX, mEventData->mScrollPosition.y, height );
- mEventData->mDecorator->SetPosition( SECONDARY_SELECTION_HANDLE, secondaryX, mEventData->mScrollPosition.y, height );
+ mEventData->mDecorator->SetPosition( LEFT_SELECTION_HANDLE, primaryX, mEventData->mScrollPosition.y, height );
+ mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE, secondaryX, mEventData->mScrollPosition.y, height );
mEventData->mDecorator->ClearHighlights();
mEventData->mDecorator->AddHighlight( primaryX, mEventData->mScrollPosition.y, secondaryX, height + mEventData->mScrollPosition.y );
{
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
mEventData->mDecorator->StopCursorBlink();
- mEventData->mDecorator->SetGrabHandleActive( false );
- mEventData->mDecorator->SetSelectionActive( false );
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
mEventData->mDecorator->SetPopupActive( false );
mEventData->mDecoratorUpdated = true;
}
{
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
mEventData->mDecorator->StopCursorBlink();
- mEventData->mDecorator->SetGrabHandleActive( false );
- mEventData->mDecorator->SetSelectionActive( true );
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true );
mEventData->mDecoratorUpdated = true;
}
else if( EventData::EDITING == mEventData->mState )
}
if( mEventData->mGrabHandleEnabled )
{
- mEventData->mDecorator->SetGrabHandleActive( true );
+ mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
}
if( mEventData->mGrabHandlePopupEnabled )
{
mEventData->mDecorator->SetPopupActive( false );
}
- mEventData->mDecorator->SetSelectionActive( false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
mEventData->mDecoratorUpdated = true;
}
else if( EventData::EDITING_WITH_POPUP == mEventData->mState )
}
if( mEventData->mGrabHandleEnabled )
{
- mEventData->mDecorator->SetGrabHandleActive( true );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true );
}
if( mEventData->mGrabHandlePopupEnabled )
{
mEventData->mDecorator->SetPopupActive( true );
}
- mEventData->mDecorator->SetSelectionActive( false );
+ mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+ mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
mEventData->mDecoratorUpdated = true;
}
}
GetCursorPosition( mEventData->mPrimaryCursorPosition,
cursorInfo );
+ const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
+ const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
+
+ // Sets the cursor position.
mEventData->mDecorator->SetPosition( PRIMARY_CURSOR,
- cursorInfo.primaryPosition.x + mEventData->mScrollPosition.x + mAlignmentOffset.x,
- cursorInfo.primaryPosition.y + mEventData->mScrollPosition.y + mAlignmentOffset.y,
+ cursorPosition.x,
+ cursorPosition.y,
cursorInfo.primaryCursorHeight,
cursorInfo.lineHeight );
+ // Sets the grab handle position.
+ mEventData->mDecorator->SetPosition( GRAB_HANDLE,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.lineHeight );
+
if( cursorInfo.isSecondaryCursor )
{
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_BOTH );
mEventData->mDecorator->SetPosition( SECONDARY_CURSOR,
- cursorInfo.secondaryPosition.x + mEventData->mScrollPosition.x + mAlignmentOffset.x,
- cursorInfo.secondaryPosition.y + mEventData->mScrollPosition.y + mAlignmentOffset.y,
+ cursorInfo.secondaryPosition.x + offset.x,
+ cursorInfo.secondaryPosition.y + offset.y,
cursorInfo.secondaryCursorHeight,
cursorInfo.lineHeight );
}
{
mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
}
+}
+
+void Controller::Impl::UpdateSelectionHandle( HandleType handleType )
+{
+ if( ( LEFT_SELECTION_HANDLE != handleType ) &&
+ ( RIGHT_SELECTION_HANDLE != handleType ) )
+ {
+ return;
+ }
+
+ const bool leftSelectionHandle = LEFT_SELECTION_HANDLE == handleType;
+ const CharacterIndex index = leftSelectionHandle ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition;
- mEventData->mUpdateCursorPosition = false;
- mEventData->mDecoratorUpdated = true;
+ CursorInfo cursorInfo;
+ GetCursorPosition( index,
+ cursorInfo );
+
+ const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
+ const Vector2 cursorPosition = cursorInfo.primaryPosition + offset;
+
+ // Sets the grab handle position.
+ mEventData->mDecorator->SetPosition( handleType,
+ cursorPosition.x,
+ cursorPosition.y,
+ cursorInfo.lineHeight );
}
void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )