fixed bug (copy&paste display error)
authorChulheon <ch.jeong47@samsung.com>
Tue, 9 Apr 2013 11:37:21 +0000 (20:37 +0900)
committerChulheon <ch.jeong47@samsung.com>
Tue, 9 Apr 2013 11:40:56 +0000 (20:40 +0900)
Change-Id: I66ab81e6a34976140c3bbdbe899934cfa46a5b48

src/ui/controls/FUiCtrl_EditCopyPasteManager.cpp

index 3c9cbbd..abb1ad7 100755 (executable)
@@ -379,6 +379,7 @@ private:
        _VisualElement* __pRoot;
        Bitmap* __pHandlerBitmap;
        FloatPoint __touchPressedPoint;
+       FloatPoint __absoluteTouchPressedPoint;
        _EditCopyPasteManager* __pCopyPasteManager;
        bool __leftHandler;
        bool __reverseCheck;
@@ -500,6 +501,7 @@ _EditCopyPasteHandler::_EditCopyPasteHandler(const Point& point, int handlerCurs
        : __pRoot(null)
        , __pHandlerBitmap(null)
        , __touchPressedPoint(0.0f, 0.0f)
+       , __absoluteTouchPressedPoint(0.0f, 0.0f)
        , __pCopyPasteManager(pCopyPasteManager)
        , __leftHandler(leftHandler)
        , __reverseCheck(false)
@@ -544,6 +546,7 @@ _EditCopyPasteHandler::_EditCopyPasteHandler(const FloatPoint& point, int handle
        : __pRoot(null)
        , __pHandlerBitmap(null)
        , __touchPressedPoint(0.0f, 0.0f)
+       , __absoluteTouchPressedPoint(0.0f, 0.0f)
        , __pCopyPasteManager(pCopyPasteManager)
        , __leftHandler(leftHandler)
        , __reverseCheck(false)
@@ -816,6 +819,7 @@ _EditCopyPasteHandler::OnTouchPressed(const _Control& source, const _TouchInfo&
        CreateCopyPasteMagnifier();
 #endif
        __touchPressedPoint = touchinfo.GetCurrentPosition();
+       __absoluteTouchPressedPoint = FloatPoint(GetBoundsF().x + __touchPressedPoint.x, GetBoundsF().y + __touchPressedPoint.y);
        __isTouchPressed = true;
        Invalidate();
        return true;
@@ -1052,6 +1056,7 @@ _EditCopyPasteHandler::OnTouchReleased(const _Control& source, const _TouchInfo&
        CheckReverseStatus();
        __isTouchPressed = false;
        __isTouchMoving = false;
+       __absoluteTouchPressedPoint = FloatPoint(0.0f, 0.0f);
        DestroyCopyPasteMagnifier();
        __pCopyPasteManager->CreateCopyPastePopup();
        __pCopyPasteManager->Show();
@@ -1072,108 +1077,216 @@ _EditCopyPasteHandler::OnTouchMoved(const _Control& source, const _TouchInfo& to
        FloatPoint touchPoint(0.0f, 0.0f);
        FloatPoint checkPoint(0.0f, 0.0f);
        __isTouchMoving = true;
+       bool cursorChange = false;
 
        _Edit* pEdit = __pCopyPasteManager->GetEdit();
        SysTryReturn(NID_UI_CTRL, pEdit, false, E_INVALID_STATE, "[E_INVALID_STATE] pEdit is null.\n");
 
        _EditPresenter* pEditPresenter = pEdit->GetPresenter();
        SysTryReturn(NID_UI_CTRL, pEditPresenter, false, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.\n");
+
        TextObject* pTextObject = pEditPresenter->GetTextObject();
+       SysTryReturn(NID_UI_CTRL, pTextObject, false, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.\n");
+
+       int curCursorLine = pTextObject->GetLineIndexAtTextIndex(__handlerCursorPos);
+       int totalLine = pTextObject->GetTotalLineCount();
 
        if (__touchPressedPoint.x == point.x && __touchPressedPoint.y == point.y)
        {
                return true;
        }
+
        if (!__singleHandler)
        {
                previousCursorPos = __pCopyPasteManager->GetCursorPosition();
                __pCopyPasteManager->SetCursorPosition(__handlerCursorPos);
        }
+
+       FloatPoint absoluteTouchMovedPoint = FloatPoint(GetBoundsF().x + point.x, GetBoundsF().y + point.y);
        cursorRect = __pCopyPasteManager->GetCursorBoundsF(false);
        absCursorRect = __pCopyPasteManager->GetCursorBoundsF(true);
-
        touchPoint.x = cursorRect.x + (point.x - __touchPressedPoint.x);
        touchPoint.y = cursorRect.y + cursorRect.height + (point.y - __touchPressedPoint.y);
-       checkPoint.x = absCursorRect.x + (point.x - __touchPressedPoint.x);
-       checkPoint.y = absCursorRect.y + absCursorRect.height + (point.y - __touchPressedPoint.y);
        cursorPos = __pCopyPasteManager->GetCursorPositionAt(touchPoint);
 
-       //if (cursorPos == -1 || (!__pCopyPasteManager->CheckHandleBounds(FloatPoint(absCursorRect.x, absCursorRect.y + absCursorRect.height))))
-       if (cursorPos == -1 || (!__pCopyPasteManager->CheckHandleBounds(FloatPoint(checkPoint.x, checkPoint.y))))
+       if (cursorPos != -1)
        {
-               int curCursorLine = pTextObject->GetLineIndexAtTextIndex(__handlerCursorPos);
-               int totalLine = pTextObject->GetTotalLineCount();
-               FloatRectangle editVisibleArea = __pCopyPasteManager->GetEditVisibleAreaF();
+               FloatRectangle cursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
+               pEdit->CalculateAbsoluteCursorBounds(cursorPos, cursorBounds);
+               cursorChange = true;
+               checkPoint.x = cursorBounds.x;
+
+               if (absoluteTouchMovedPoint.y -__absoluteTouchPressedPoint.y >= 0.0f || totalLine == 1)
+               {
+                       checkPoint.y = cursorBounds.y + cursorBounds.height;
+               }
+               else
+               {
+                       checkPoint.y = cursorBounds.y;
+               }
+       }
 
-               if (pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE || (pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE && totalLine == 1))
+       if (cursorPos == -1 || (cursorChange && !__pCopyPasteManager->CheckHandleBounds(FloatPoint(checkPoint.x, checkPoint.y))))
+       {
+               if (cursorPos != -1)
                {
-                       if (point.x - __touchPressedPoint.x >= 0.0f) // RightSide
+                       if (totalLine == 1)
                        {
-                               if (__handlerCursorPos == pEditPresenter->GetTextLength())
+                               pTextObject->SetFirstDisplayLineIndexFromTextIndex(cursorPos);
+                       }
+                       else
+                       {
+                               if (absoluteTouchMovedPoint.y -__absoluteTouchPressedPoint.y >= 0.0f)
                                {
-                                       cursorPos = __handlerCursorPos;
+                                       if (curCursorLine < totalLine - 1)
+                                       {
+                                               if (!pTextObject->IsDisplayedLastLine())
+                                               {
+                                                       int line = pTextObject->GetFirstDisplayLineIndex();
+                                                       pTextObject->SetFirstDisplayLineIndex(line+1);
+                                               }
+                                               else
+                                               {
+                                                       if (__pCopyPasteManager->CheckHandlePosition(__leftHandler, cursorPos))
+                                                       {
+                                                               __pCopyPasteManager->SetCursorPosition(cursorPos);
+                                                               pEditPresenter->ScrollPanelToCursorPosition(true);
+                                                       }
+                                                       else
+                                                       {
+                                                               __pCopyPasteManager->SetCursorPosition(previousCursorPos);
+                                                               pEditPresenter->SetCursorChangedFlag(!__leftHandler);
+                                                               return true;
+                                                       }
+                                               }
+                                       }
                                }
                                else
                                {
-                                       cursorPos = __handlerCursorPos + 1;
-
-                                       if (!__singleHandler && __leftHandler && (cursorPos == pEditPresenter->GetTextLength()))
+                                       if (curCursorLine !=0)
                                        {
-                                               cursorPos = __handlerCursorPos;
+                                               if (!pTextObject->IsDisplayedFirstLine())
+                                               {
+                                                       int line = pTextObject->GetFirstDisplayLineIndex();
+                                                       pTextObject->SetFirstDisplayLineIndex(line-1);
+                                               }
+                                               else
+                                               {
+                                                       __pCopyPasteManager->SetCursorPosition(cursorPos);
+                                                       pEditPresenter->ScrollPanelToCursorPosition(true);
+                                               }
                                        }
                                }
                        }
-                       else //LeftSide
+               }
+               else
+               {
+                       if (totalLine == 1)
                        {
-                               if (__handlerCursorPos != 0)
+                               if (point.x - __touchPressedPoint.x == 0.0f)
                                {
-                                       cursorPos = __handlerCursorPos - 1;
+                                       __pCopyPasteManager->SetCursorPosition(previousCursorPos);
+                                       pEditPresenter->SetCursorChangedFlag(!__leftHandler);
+                                       return true;
 
-                                       if (!__singleHandler && __leftHandler)
+                               }
+                               else if (point.x - __touchPressedPoint.x > 0.0f)
+                               {
+                                       if (__handlerCursorPos == pEditPresenter->GetTextLength())
                                        {
-                                               pTextObject->SetFirstDisplayLineIndexFromTextIndex(cursorPos);
+                                               cursorPos = __handlerCursorPos;
+                                       }
+                                       else
+                                       {
+                                               cursorPos = __handlerCursorPos + 1;
+
+                                               if (!__singleHandler && __leftHandler && (cursorPos == pEditPresenter->GetTextLength()))
+                                               {
+                                                       cursorPos = __handlerCursorPos;
+                                               }
                                        }
                                }
-                       }
-                       if (point.y < 0.0f || (point.y > GetBoundsF().height))
-                       {
-                               __pCopyPasteManager->SetCursorPosition(previousCursorPos);
-                               pEditPresenter->SetCursorChangedFlag(!__leftHandler);
-                               return true;
-                       }
-               }
-               else
-               {
-                       if (point.y - __touchPressedPoint.y >= 0.0f) // DownSide
-                       {
-                               if (curCursorLine < totalLine - 1)
+                               else
                                {
-                                       int offset = __handlerCursorPos - pTextObject->GetFirstTextIndexAt(curCursorLine);
-                                       int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine+1);
-                                       cursorPos = offset + firstTextIndex;
-                                       int textLength = pTextObject->GetTextLengthAt(curCursorLine+1);
-                                       if (offset > textLength)
+                                       if (__handlerCursorPos != 0)
                                        {
-                                               cursorPos = firstTextIndex+textLength;
+                                               cursorPos = __handlerCursorPos - 1;
+
+                                               if (!__singleHandler && __leftHandler)
+                                               {
+                                                       pTextObject->SetFirstDisplayLineIndexFromTextIndex(cursorPos);
+                                               }
                                        }
-                                       int line = pTextObject->GetFirstDisplayLineIndex();
-                                       pTextObject->SetFirstDisplayLineIndex(line+1);
+                               }
+                               if (point.y < 0.0f || (point.y > GetBoundsF().height))
+                               {
+                                       __pCopyPasteManager->SetCursorPosition(previousCursorPos);
+                                       pEditPresenter->SetCursorChangedFlag(!__leftHandler);
+                                       return true;
                                }
                        }
                        else
                        {
-                               if (curCursorLine !=0)
+                               if (absoluteTouchMovedPoint.y -__absoluteTouchPressedPoint.y >= 0.0f)
                                {
-                                       int offset = __handlerCursorPos - pTextObject->GetFirstTextIndexAt(curCursorLine);
-                                       int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine-1);
-                                       cursorPos = offset + firstTextIndex;
-                                       int textLength = pTextObject->GetTextLengthAt(curCursorLine-1);
-                                       if (offset > textLength)
+                                       if (curCursorLine < totalLine - 1)
+                                       {
+                                               int offset = __handlerCursorPos - pTextObject->GetFirstTextIndexAt(curCursorLine);
+                                               int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine+1);
+                                               cursorPos = offset + firstTextIndex;
+                                               int textLength = pTextObject->GetTextLengthAt(curCursorLine+1);
+                                               if (offset > textLength)
+                                               {
+                                                       cursorPos = firstTextIndex+textLength;
+                                               }
+                                               if (!pTextObject->IsDisplayedLastLine())
+                                               {
+                                                       int line = pTextObject->GetFirstDisplayLineIndex();
+                                                       pTextObject->SetFirstDisplayLineIndex(line+1);
+                                                       __pCopyPasteManager->SetCursorPosition(cursorPos);
+                                                       pEditPresenter->ScrollPanelToCursorPosition(true);
+                                               }
+                                               else
+                                               {
+                                                       if (__pCopyPasteManager->CheckHandlePosition(__leftHandler, cursorPos))
+                                                       {
+                                                               __pCopyPasteManager->SetCursorPosition(cursorPos);
+                                                               pEditPresenter->ScrollPanelToCursorPosition(true);
+                                                       }
+                                                       else
+                                                       {
+                                                               __pCopyPasteManager->SetCursorPosition(previousCursorPos);
+                                                               pEditPresenter->SetCursorChangedFlag(!__leftHandler);
+                                                               return true;
+                                                       }
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       if (curCursorLine !=0)
                                        {
-                                               cursorPos = firstTextIndex+textLength;
+                                               int offset = __handlerCursorPos - pTextObject->GetFirstTextIndexAt(curCursorLine);
+                                               int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine-1);
+                                               cursorPos = offset + firstTextIndex;
+                                               int textLength = pTextObject->GetTextLengthAt(curCursorLine-1);
+                                               if (offset > textLength)
+                                               {
+                                                       cursorPos = firstTextIndex+textLength;
+                                               }
+                                               if (!pTextObject->IsDisplayedFirstLine())
+                                               {
+                                                       int line = pTextObject->GetFirstDisplayLineIndex();
+                                                       pTextObject->SetFirstDisplayLineIndex(line-1);
+                                                       __pCopyPasteManager->SetCursorPosition(cursorPos);
+                                                       pEditPresenter->ScrollPanelToCursorPosition(true);
+                                               }
+                                               else
+                                               {
+                                                       __pCopyPasteManager->SetCursorPosition(cursorPos);
+                                                       pEditPresenter->ScrollPanelToCursorPosition(true);
+                                               }
                                        }
-                                       int line = pTextObject->GetFirstDisplayLineIndex();
-                                       pTextObject->SetFirstDisplayLineIndex(line-1);
                                }
                        }
                }
@@ -2066,7 +2179,7 @@ _EditCopyPasteManager::RefreshBlock(bool isLeftHandle)
        int rightHandlerPos = __pHandle[HANDLER_TYPE_RIGHT]->GetHandlerCursorPosition();
 
        __pEdit->SetBlockRange(leftHandlerPos, rightHandlerPos);
-       __pEditPresenter->SetCursorChangedFlag(false);//!isLeftHandle);
+       __pEditPresenter->SetCursorChangedFlag(!isLeftHandle);
        __pEditPresenter->DrawText();
        AdjustBounds();
 }