80ea8185f0dbb406946f71e9af5ad93725201729
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_EditCopyPasteManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_EditCopyPasteManager.cpp
20  * @brief               This is the implementation file for the _EditCopyPasteManager class.
21  */
22
23 #include "FUiAnim_ControlVisualElement.h"
24 #include "FUiAnim_VisualElementImpl.h"
25 #include <appsvc/appsvc.h>
26 #include <FApp_AppControlManager.h>
27 #include <FApp_AppMessageImpl.h>
28 #include <FBaseUtilMath.h>
29 #include <FGrp_BitmapImpl.h>
30 #include "FUi_Clipboard.h"
31 #include "FUi_ClipboardItem.h"
32 #include "FUi_CoordinateSystemUtils.h"
33 #include "FUi_EcoreEvasMgr.h"
34 #include "FUiCtrl_EditCopyPasteManager.h"
35 #include "FUiCtrl_EditCopyPasteEvent.h"
36 #include "FUiCtrl_EditPresenter.h"
37 #include "FUiCtrl_Form.h"
38 #include "FUiCtrl_Frame.h"
39 #include "FUi_EcoreEvas.h"
40 #include "FUi_Math.h"
41 #include "FUi_Window.h"
42
43 #define EDIT_COPY_PASTE_MAGNIFIER 1
44
45 using namespace Tizen::Ui;
46 using namespace Tizen::App;
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Runtime;
49 using namespace Tizen::Base::Utility;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::Graphics::_Text;
52 using namespace Tizen::Ui::Animations;
53
54 namespace Tizen { namespace Ui { namespace Controls
55 {
56
57 const int COPY_PASTE_SELECT_ID = 231;
58 const int COPY_PASTE_SELECT_ALL_ID = 232;
59 const int COPY_PASTE_COPY_ID = 233;
60 const int COPY_PASTE_CUT_ID = 234;
61 const int COPY_PASTE_PASTE_ID = 235;
62 const int COPY_PASTE_CLIPBOARD_ID = 236;
63 const int COPY_PASTE_SEARCH_ID = 237;
64
65 class _EditCopyPasteMagnifier
66         : public _Window
67 {
68 public:
69         _EditCopyPasteMagnifier(_EditCopyPasteManager* pCopyPasteManager, int handlerCursorPos);
70         virtual ~_EditCopyPasteMagnifier(void);
71         static _EditCopyPasteMagnifier* CreateInstanceN(const FloatPoint& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager);
72         virtual void OnDraw(void);
73         void CaptureTextArea(Canvas& canvas);
74         void MoveMagnifier(const FloatPoint& point, int handlerCursorPos);
75         Bitmap* GetMagnifierBitmap(void) const;
76         virtual result OnAttachedToMainTree(void);
77         void SetRowColumnIndex(int rowIndex, int columnIndex);
78
79 private:
80         _EditCopyPasteMagnifier(const _EditCopyPasteMagnifier& value);
81         _EditCopyPasteMagnifier& operator =(const _EditCopyPasteMagnifier& value);
82
83 private:
84         _EditCopyPasteManager* __pCopyPasteManager;
85         Bitmap* __pMagnifierBitmap;
86         Bitmap* __pMagnifierMaskBitmap;
87         _VisualElement* __pRoot;
88         int __handlerCursorPos;
89         int __rowIndex;
90         int __columnIndex;
91 };
92
93 _EditCopyPasteMagnifier::_EditCopyPasteMagnifier(_EditCopyPasteManager* pCopyPasteManager, int handlerCursorPos)
94         : __pCopyPasteManager(pCopyPasteManager)
95         , __pMagnifierBitmap(null)
96         , __pMagnifierMaskBitmap(null)
97         , __pRoot(null)
98         , __handlerCursorPos(handlerCursorPos)
99         , __rowIndex(-1)
100         , __columnIndex(-1)
101 {
102         AcquireHandle();
103         __pRoot = GetVisualElement();
104         __pRoot->SetSurfaceOpaque(false);
105
106         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_MAGNIFIER, BITMAP_PIXEL_FORMAT_ARGB8888, __pMagnifierBitmap);
107         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_MAGNIFIER_MASK, BITMAP_PIXEL_FORMAT_ARGB8888, __pMagnifierMaskBitmap);
108 }
109
110 _EditCopyPasteMagnifier::~_EditCopyPasteMagnifier(void)
111 {
112         if (__pMagnifierBitmap)
113         {
114                 delete __pMagnifierBitmap;
115                 __pMagnifierBitmap = null;
116         }
117         if (__pMagnifierMaskBitmap)
118         {
119                 delete __pMagnifierMaskBitmap;
120                 __pMagnifierMaskBitmap = null;
121         }
122 }
123
124 Bitmap*
125 _EditCopyPasteMagnifier::GetMagnifierBitmap(void) const
126 {
127         return __pMagnifierBitmap;
128 }
129
130 _EditCopyPasteMagnifier*
131 _EditCopyPasteMagnifier::CreateInstanceN(const FloatPoint& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager)
132 {
133         _EditCopyPasteMagnifier* pCopyPasteMagnifier = new (std::nothrow) _EditCopyPasteMagnifier(pCopyPasteManager, handlerCursorPos);
134         SysTryReturn(NID_UI_CTRL, pCopyPasteMagnifier != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
135
136         FloatPoint cursorPoint(point);
137         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
138         float width = 0.0f;
139         float height = 0.0f;
140         _Edit* pEdit = pCopyPasteManager->GetEdit();
141         _ControlOrientation orientation = pEdit->GetOrientation();
142
143         Bitmap* pMagnifierBitmap = pCopyPasteMagnifier->GetMagnifierBitmap();
144         SysTryReturn(NID_UI_CTRL, pMagnifierBitmap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
145
146         result r = pCopyPasteMagnifier->CreateRootVisualElement(_WINDOW_TYPE_VE);
147         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
148
149         pCopyPasteMagnifier->SetActivationEnabled(false);
150
151         GET_SHAPE_CONFIG(EDIT::COPYPASTE_MAGNIFIER_WIDTH, orientation, width);
152         GET_SHAPE_CONFIG(EDIT::COPYPASTE_MAGNIFIER_HEIGHT, orientation, height);
153
154         bounds = FloatRectangle(cursorPoint.x - width/2.0f, cursorPoint.y - height, width, height);
155         if (bounds.y < 0.0f)
156         {
157                 bounds.y = 0.0f;
158         }
159         pCopyPasteMagnifier->Open();
160         pCopyPasteMagnifier->SetBounds(bounds);
161
162         return pCopyPasteMagnifier;
163
164 CATCH:
165         pCopyPasteMagnifier->Close();
166         delete pCopyPasteMagnifier;
167
168         return null;
169 }
170
171 result
172 _EditCopyPasteMagnifier::OnAttachedToMainTree(void)
173 {
174         result r = E_SUCCESS;
175
176         if (GetOwner() == null)
177         {
178                 _Edit* pEdit = __pCopyPasteManager->GetEdit();
179                 SysTryReturnResult(NID_UI_CTRL, pEdit, GetLastResult(), "Unable to get pEdit.");
180
181                 _Window* pWindow = null;
182                 _Control* pControlCore = null;
183
184                 for (pControlCore = pEdit->GetParent(); pWindow == null; pControlCore = pControlCore->GetParent())
185                 {
186                         if (pControlCore == null)
187                         {
188                                 break;
189                         }
190
191                         pWindow = dynamic_cast<_Window*>(pControlCore);
192                         if (pWindow)
193                         {
194                                 SetOwner(pWindow);
195                                 return r;
196                         }
197                 }
198
199                 _EditPresenter* pEditPresenter = pEdit->GetPresenter();
200                 SysTryReturnResult(NID_UI_CTRL, pEdit, GetLastResult(), "Unable to get pEditPresenter.");
201
202                 _Form* pParentForm = pEditPresenter->GetParentForm();
203                 if (pParentForm)
204                 {
205                         SetOwner(pParentForm);
206                 }
207                 else
208                 {
209                         _Form* pForm = null;
210                         _Frame* pCurrentFrame = dynamic_cast <_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
211                         if (pCurrentFrame)
212                         {
213                                 pForm = pCurrentFrame->GetCurrentForm();
214                                 if (pForm)
215                                 {
216                                         SetOwner(pForm);
217                                 }
218                                 else
219                                 {
220                                         SetOwner(pCurrentFrame);
221                                 }
222                         }
223                 }
224         }
225
226         return r;
227 }
228
229 void
230 _EditCopyPasteMagnifier::OnDraw(void)
231 {
232         Canvas* pCanvas = GetCanvasN();
233         if (pCanvas == null)
234         {
235                 return;
236         }
237         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
238         pCanvas->Clear();
239         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pMagnifierBitmap))
240         {
241                 pCanvas->DrawNinePatchedBitmap(pCanvas->GetBoundsF(), *__pMagnifierBitmap);
242         }
243         else
244         {
245                 pCanvas->DrawBitmap(pCanvas->GetBoundsF(), *__pMagnifierBitmap);
246         }
247
248         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pMagnifierMaskBitmap))
249         {
250                 Color editColor = __pCopyPasteManager->GetEdit()->GetColor(EDIT_STATUS_HIGHLIGHTED);
251                 if (editColor.GetAlpha() == 0x00)
252                 {
253                         byte r,g,b,a;
254                         editColor = __pCopyPasteManager->GetEdit()->GetTextColor(EDIT_STATUS_HIGHLIGHTED);
255                         editColor.GetColorComponents(r,g,b,a);
256                         byte max = (r >= g) ? r:g;
257                         max = (max >= b) ? max:b;
258                         if (max >= 255/2)
259                         {
260                                 editColor = Color::GetColor(COLOR_ID_BLACK);
261                         }
262                         else
263                         {
264                                 editColor = Color::GetColor(COLOR_ID_WHITE);
265                         }
266                 }
267
268                 Bitmap* pReplacedMaskBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pMagnifierMaskBitmap, Color::GetColor(COLOR_ID_MAGENTA), editColor);
269                 SysTryCatch(NID_UI_CTRL, pReplacedMaskBitmap, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
270
271                 pCanvas->DrawNinePatchedBitmap(pCanvas->GetBoundsF(), *pReplacedMaskBitmap);
272
273                 delete pReplacedMaskBitmap;
274         }
275         else
276         {
277                 pCanvas->DrawBitmap(pCanvas->GetBoundsF(), *__pMagnifierMaskBitmap);
278         }
279
280         CaptureTextArea(*pCanvas);
281
282         delete pCanvas;
283
284         return;
285
286 CATCH:
287         delete pCanvas;
288
289         return;
290 }
291
292 void
293 _EditCopyPasteMagnifier::CaptureTextArea(Canvas& canvas)
294 {
295         result r = E_SUCCESS;
296         float captureWidth = 0.0f;
297         float captureHeight = 0.0f;
298         float capturePosX = 0.0f;
299         float capturePosY = 0.0f;
300         float adjustPosX = 0.0f;
301         float adjustPosY = 0.0f;
302         FloatRectangle cursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
303         FloatRectangle captureBounds(0.0f, 0.0f, 0.0f, 0.0f);
304         _VisualElementImpl* pEditVisualElementImpl = null;
305
306         _Edit* pEdit = __pCopyPasteManager->GetEdit();
307         SysTryReturnVoidResult(NID_UI_CTRL, pEdit, E_INVALID_STATE, "[E_INVALID_STATE] pEdit is null.");
308
309         _VisualElement* pEditVisualElement = pEdit->GetVisualElement();
310         SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement, E_INVALID_STATE, "[E_INVALID_STATE] pEditVisualElement is null.");
311
312         _EditPresenter* pEditPresenter = pEdit->GetPresenter();
313         SysTryReturnVoidResult(NID_UI_CTRL, pEditPresenter, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.");
314
315         if (__rowIndex >= 0 && __columnIndex >= 0)
316         {
317                 pEditPresenter->CalculateCursorBounds(pEditPresenter->GetTextBoundsF(), cursorBounds, __rowIndex, __columnIndex);
318         }
319         else
320         {
321                 pEditPresenter->CalculateCursorBounds(pEditPresenter->GetTextBoundsF(), cursorBounds,__handlerCursorPos);
322         }
323
324         GET_SHAPE_CONFIG(EDIT::COPYPASTE_MAGNIFIER_CAPTURE_WIDTH, pEdit->GetOrientation(), captureWidth);
325         GET_SHAPE_CONFIG(EDIT::COPYPASTE_MAGNIFIER_CAPTURE_HEIGHT, pEdit->GetOrientation(), captureHeight);
326         GET_SHAPE_CONFIG(EDIT::COPYPASTE_MAGNIFIER_CAPTURE_POSITION_X, pEdit->GetOrientation(), capturePosX);
327         GET_SHAPE_CONFIG(EDIT::COPYPASTE_MAGNIFIER_CAPTURE_POSITION_Y, pEdit->GetOrientation(), capturePosY);
328
329         FloatRectangle textObjectBounds = pEditPresenter->GetTextBoundsF();
330
331         // textobject minimum width/height
332         if (pEdit->GetBoundsF().width < textObjectBounds.width)
333         {
334                 textObjectBounds.width = pEdit->GetBoundsF().width - pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN) - pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
335         }
336
337         captureBounds.x = cursorBounds.x + cursorBounds.width/2.0f - captureWidth/2.0f;
338         captureBounds.y = cursorBounds.y + cursorBounds.height/2.0f - captureHeight/2.0f;
339         captureBounds.width = captureWidth;
340         captureBounds.height = captureHeight;
341         captureBounds = textObjectBounds.GetIntersection(captureBounds);
342
343         if ((cursorBounds.x + cursorBounds.width/2.0f) - captureBounds.x < captureWidth/2.0f)
344         {
345                 adjustPosX = captureWidth/2.0f - (cursorBounds.x + cursorBounds.width/2.0f - captureBounds.x);
346         }
347
348         if (captureBounds.height < captureHeight && captureBounds.y < captureHeight)
349         {
350                 adjustPosY = captureHeight - captureBounds.height;
351         }
352
353         Bitmap* pOriginalBitmp = null;
354         Canvas* pCanvas = new (std::nothrow) Canvas;
355         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
356
357         r = pCanvas->Construct(FloatRectangle(0, 0, captureBounds.width, captureBounds.height));
358         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
359
360         pEditVisualElementImpl = _VisualElementImpl::GetInstance(*pEditVisualElement);
361
362         pEditVisualElementImpl->Capture(*pCanvas, CoordinateSystem::AlignToDevice(FloatRectangle(0, 0, captureBounds.width, captureBounds.height)), CoordinateSystem::AlignToDevice(captureBounds), true);
363
364         pOriginalBitmp = new (std::nothrow) Bitmap;
365         SysTryCatch(NID_UI, pOriginalBitmp != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
366
367         r = pOriginalBitmp->Construct(*pCanvas, CoordinateSystem::AlignToDevice(FloatRectangle(0, 0, captureBounds.width, captureBounds.height)));
368
369         r = pOriginalBitmp->SetScalingQuality(BITMAP_SCALING_QUALITY_HIGH);
370         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
371
372         r = pOriginalBitmp->Scale(CoordinateSystem::AlignToDevice(FloatDimension(pOriginalBitmp->GetActualWidth()*1.5f, pOriginalBitmp->GetActualHeight()*1.5f)));
373         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
374
375         canvas.DrawBitmap(CoordinateSystem::AlignToDevice(FloatPoint(capturePosX + adjustPosX*1.5f, capturePosY + adjustPosY*1.5f)), *pOriginalBitmp);
376
377         delete pCanvas;
378         delete pOriginalBitmp;
379
380         return;
381
382 CATCH:
383         delete pCanvas;
384         delete pOriginalBitmp;
385
386         return;
387 }
388
389 void
390 _EditCopyPasteMagnifier::MoveMagnifier(const FloatPoint& point, int handlerCursorPos)
391 {
392         FloatRectangle bounds = FloatRectangle(point.x - GetBoundsF().width/2.0f, point.y - GetBoundsF().height, GetBoundsF().width, GetBoundsF().height);
393         __handlerCursorPos = handlerCursorPos;
394         if (bounds.y < 0.0f)
395         {
396                 bounds.y = 0.0f;
397         }
398         SetBounds(bounds);
399         Invalidate();
400 }
401
402 void
403 _EditCopyPasteMagnifier::SetRowColumnIndex(int rowIndex, int columnIndex)
404 {
405         __rowIndex = rowIndex;
406         __columnIndex = columnIndex;
407 }
408
409 /**
410 * @class        _EditCopyPasteHandler
411 * @brief        This class defines the common behavior for the %_EditCopyPasteHandler.
412 *
413 */
414 class _EditCopyPasteHandler
415         : public _Window
416         , virtual public IEventListener
417         , virtual public _IUiEventListener
418         , virtual public _IUiEventPreviewer
419 {
420
421 // Lifecycle
422 public:
423         /**
424         * This is the default class constructor.
425         *
426         */
427         _EditCopyPasteHandler(const Point& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler);
428         _EditCopyPasteHandler(const FloatPoint& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler);
429
430         /**
431         * This is the default class destructor.
432         *
433         */
434         virtual ~_EditCopyPasteHandler(void);
435
436 // Operations
437 public:
438         enum HandlerDirection
439         {
440                 HANDLER_DIRECTION_NONE = 0,
441                 HANDLER_DIRECTION_REVERSE_1,//horizontal reverse
442                 HANDLER_DIRECTION_REVERSE_2,//vertical reverse
443                 HANDLER_DIRECTION_REVERSE_3,//horizontal vertical reverse
444         };
445
446         static _EditCopyPasteHandler* CreateInstanceN(const Point& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler = true);
447         static _EditCopyPasteHandler* CreateInstanceN(const FloatPoint& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler = true);
448         int GetHandlerCursorPosition(void) const;
449         void SetHandlerRowColumnIndex(int rowIndex, int columnIndex);
450         void GetHandlerRowColumnIndex(int& rowIndex, int& columnIndex) const;
451         void SetHandlerCursorPosition(int handlerCursorPos);
452         void AdjustBounds(void);
453         void CheckReverseStatus(void);
454         void ChangeHandlerBitmap(void);
455         Bitmap* GetHandlerBitmap(void) const;
456         bool CreateCopyPasteMagnifier(void);
457         void DestroyCopyPasteMagnifier(void);
458         void MoveCopyPasteMagnifier(void);
459         void UpdateCopyPasteMagnifier(void);
460
461 // virtual function
462         virtual void OnDraw(void);
463         virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo);
464         virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo);
465         virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo);
466         virtual bool IsActivatedOnOpen(void) const;
467         virtual void OnChangeLayout(_ControlOrientation orientation);
468         virtual result OnAttachedToMainTree(void);
469
470
471 private:
472         _EditCopyPasteHandler(const _EditCopyPasteHandler& value);
473         _EditCopyPasteHandler& operator =(const _EditCopyPasteHandler& value);
474
475 // Attribute
476 private:
477         _VisualElement* __pRoot;
478         Bitmap* __pHandlerBitmap;
479         FloatPoint __touchPressedPoint;
480         FloatPoint __absoluteTouchPressedPoint;
481         _EditCopyPasteManager* __pCopyPasteManager;
482         bool __leftHandler;
483         bool __reverseCheck;
484         int __handlerCursorPos;
485         bool __isTouchPressed;
486         HandlerDirection __handlerDirection;
487         bool __singleHandler;
488         _EditCopyPasteMagnifier* __pCopyPasteMagnifier;
489         bool __isTouchMoving;
490         int __rowIndex;
491         int __columnIndex;
492 }; // _EditCopyPasteHandler
493
494 Bitmap*
495 _EditCopyPasteHandler::GetHandlerBitmap(void) const
496 {
497         return __pHandlerBitmap;
498 }
499
500 bool
501 _EditCopyPasteHandler::CreateCopyPasteMagnifier(void)
502 {
503         if (!__pCopyPasteMagnifier)
504         {
505                 _Edit* pEdit = __pCopyPasteManager->GetEdit();
506                 SysTryReturn(NID_UI_CTRL, pEdit, false, E_INVALID_STATE, "[E_INVALID_STATE] pEdit is null.\n");
507
508                 _EditPresenter* pEditPresenter = pEdit->GetPresenter();
509                 SysTryReturn(NID_UI_CTRL, pEditPresenter, false, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.\n");
510
511                 FloatRectangle cursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
512                 if (__rowIndex >= 0 && __columnIndex >= 0)
513                 {
514                         pEditPresenter->CalculateAbsoluteCursorBounds(__rowIndex, __columnIndex, cursorBounds);
515                 }
516                 else
517                 {
518                         pEditPresenter->CalculateAbsoluteCursorBounds(__handlerCursorPos, cursorBounds);
519                 }
520                 __pCopyPasteMagnifier = _EditCopyPasteMagnifier::CreateInstanceN(FloatPoint(cursorBounds.x, cursorBounds.y), __handlerCursorPos, __pCopyPasteManager);
521                 SysTryReturn(NID_UI_CTRL, __pCopyPasteMagnifier, false, E_INVALID_STATE, "[E_INVALID_STATE] __pCopyPasteMagnifier is null.\n");
522
523                 __pCopyPasteMagnifier->SetRowColumnIndex(__rowIndex, __columnIndex);
524         }
525         return true;
526 }
527
528 void
529 _EditCopyPasteHandler::DestroyCopyPasteMagnifier(void)
530 {
531         if (__pCopyPasteMagnifier)
532         {
533                 __pCopyPasteMagnifier->Close();
534                 delete __pCopyPasteMagnifier;
535                 __pCopyPasteMagnifier = null;
536         }
537 }
538
539 void
540 _EditCopyPasteHandler::MoveCopyPasteMagnifier(void)
541 {
542         if (__pCopyPasteMagnifier)
543         {
544                 _Edit* pEdit = __pCopyPasteManager->GetEdit();
545                 SysTryReturnVoidResult(NID_UI_CTRL, pEdit, E_INVALID_STATE, "[E_INVALID_STATE] pEdit is null.");
546
547                 _EditPresenter* pEditPresenter = pEdit->GetPresenter();
548                 SysTryReturnVoidResult(NID_UI_CTRL, pEditPresenter, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.");
549
550                 FloatRectangle cursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
551                 if (__rowIndex >= 0 && __columnIndex >= 0)
552                 {
553                         pEditPresenter->CalculateAbsoluteCursorBounds(__rowIndex, __columnIndex, cursorBounds);
554                 }
555                 else
556                 {
557                         pEditPresenter->CalculateAbsoluteCursorBounds(__handlerCursorPos, cursorBounds);
558                 }
559                 __pCopyPasteMagnifier->SetRowColumnIndex(__rowIndex, __columnIndex);
560                 __pCopyPasteMagnifier->MoveMagnifier(FloatPoint(cursorBounds.x, cursorBounds.y), __handlerCursorPos);
561         }
562 }
563
564 void
565 _EditCopyPasteHandler::UpdateCopyPasteMagnifier(void)
566 {
567         if (__pCopyPasteMagnifier)
568         {
569                 __pCopyPasteMagnifier->Invalidate();
570         }
571 }
572
573 void
574 _EditCopyPasteHandler::ChangeHandlerBitmap(void)
575 {
576         if (__pHandlerBitmap)
577         {
578                 delete __pHandlerBitmap;
579                 __pHandlerBitmap = null;
580         }
581         if (__singleHandler)
582         {
583                 if (__handlerDirection == HANDLER_DIRECTION_NONE)
584                 {
585                         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_CENTER_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
586                 }
587                 else
588                 {
589                         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_REVERSE_CENTER_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
590                 }
591                 return;
592         }
593         if (__leftHandler)
594         {
595                 switch(__handlerDirection)
596                 {
597                         case HANDLER_DIRECTION_REVERSE_1:
598                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_RIGHT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
599                                 break;
600                         case HANDLER_DIRECTION_REVERSE_2:
601                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_REVERSE_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
602                                 break;
603                         case HANDLER_DIRECTION_REVERSE_3:
604                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_REVERSE_RIGHT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
605                                 break;
606                         case HANDLER_DIRECTION_NONE:
607                                 //fall through
608                         default:
609                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
610                                 break;
611                 }
612         }
613         else
614         {
615                 switch(__handlerDirection)
616                 {
617                         case HANDLER_DIRECTION_REVERSE_1:
618                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
619                                 break;
620                         case HANDLER_DIRECTION_REVERSE_2:
621                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_REVERSE_RIGHT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
622                                 break;
623                         case HANDLER_DIRECTION_REVERSE_3:
624                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_REVERSE_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
625                                 break;
626                         case HANDLER_DIRECTION_NONE:
627                                 //fall through
628                         default:
629                                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_RIGHT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
630                                 break;
631                 }
632         }
633 }
634
635 _EditCopyPasteHandler::_EditCopyPasteHandler(const Point& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler)
636         : __pRoot(null)
637         , __pHandlerBitmap(null)
638         , __touchPressedPoint(0.0f, 0.0f)
639         , __absoluteTouchPressedPoint(0.0f, 0.0f)
640         , __pCopyPasteManager(pCopyPasteManager)
641         , __leftHandler(leftHandler)
642         , __reverseCheck(false)
643         , __handlerCursorPos(handlerCursorPos)
644         , __isTouchPressed(false)
645         , __handlerDirection(HANDLER_DIRECTION_NONE)
646         , __singleHandler(false)
647         , __pCopyPasteMagnifier(null)
648         , __isTouchMoving(false)
649         , __rowIndex(-1)
650         , __columnIndex(-1)
651 {
652         AcquireHandle();
653
654         __pRoot = GetVisualElement();
655         __pRoot->SetSurfaceOpaque(false);
656
657         Point handlerPoint(point);
658
659         if (singleHandler)
660         {
661                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_CENTER_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
662                 handlerPoint.x = handlerPoint.x - (__pHandlerBitmap->GetWidth() / 2);
663                 __singleHandler = true;
664         }
665         else
666         {
667                 if (leftHandler)
668                 {
669                         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
670                         handlerPoint.x = handlerPoint.x - __pHandlerBitmap->GetWidth();
671                 }
672                 else
673                 {
674                         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_RIGHT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
675                 }
676         }
677
678         FloatRectangle bounds(handlerPoint.x, handlerPoint.y, __pHandlerBitmap->GetWidth(), __pHandlerBitmap->GetHeight());
679 }
680
681 _EditCopyPasteHandler::_EditCopyPasteHandler(const FloatPoint& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler)
682         : __pRoot(null)
683         , __pHandlerBitmap(null)
684         , __touchPressedPoint(0.0f, 0.0f)
685         , __absoluteTouchPressedPoint(0.0f, 0.0f)
686         , __pCopyPasteManager(pCopyPasteManager)
687         , __leftHandler(leftHandler)
688         , __reverseCheck(false)
689         , __handlerCursorPos(handlerCursorPos)
690         , __isTouchPressed(false)
691         , __handlerDirection(HANDLER_DIRECTION_NONE)
692         , __singleHandler(false)
693         , __pCopyPasteMagnifier(null)
694         , __isTouchMoving(false)
695         , __rowIndex(-1)
696         , __columnIndex(-1)
697 {
698         AcquireHandle();
699
700 //To do .....
701
702         //Point handlerPoint(_CoordinateSystemUtils::ConvertToInteger(point));
703         FloatPoint handlerPoint(point);
704         if (singleHandler)
705         {
706                 GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_CENTER_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
707                 handlerPoint.x = handlerPoint.x - (__pHandlerBitmap->GetWidthF() / 2.0f);
708                 __singleHandler = true;
709         }
710         else
711         {
712                 if (leftHandler)
713                 {
714                         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
715                         handlerPoint.x = handlerPoint.x - __pHandlerBitmap->GetWidthF();
716                 }
717                 else
718                 {
719                         GET_BITMAP_CONFIG_N(EDIT::COPY_PASTE_ICON_RIGHT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
720                 }
721         }
722
723         FloatRectangle bounds(handlerPoint.x, handlerPoint.y, _CoordinateSystemUtils::ConvertToFloat(__pHandlerBitmap->GetWidth()), _CoordinateSystemUtils::ConvertToFloat(__pHandlerBitmap->GetHeight()));
724 }
725
726 _EditCopyPasteHandler::~_EditCopyPasteHandler(void)
727 {
728         DestroyCopyPasteMagnifier();
729
730         if (__pHandlerBitmap)
731         {
732                 delete __pHandlerBitmap;
733                 __pHandlerBitmap = null;
734         }
735 }
736
737 _EditCopyPasteHandler*
738 _EditCopyPasteHandler::CreateInstanceN(const Point& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler)
739 {
740         _EditCopyPasteHandler* pCopyPasteHandler = new (std::nothrow) _EditCopyPasteHandler(point, handlerCursorPos, pCopyPasteManager, singleHandler, leftHandler);
741         SysTryReturn(NID_UI_CTRL, pCopyPasteHandler != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
742
743         Point handlerPoint(point);
744         Rectangle bounds(0, 0, 0, 0);
745         Bitmap* pHandlerBitmap = pCopyPasteHandler->GetHandlerBitmap();
746
747         result r = pCopyPasteHandler->CreateRootVisualElement(_WINDOW_TYPE_VE);
748         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
749
750         pCopyPasteHandler->SetActivationEnabled(false);
751
752         if (singleHandler)
753         {
754                 handlerPoint.x = handlerPoint.x - (pHandlerBitmap->GetWidth() / 2);
755         }
756         else
757         {
758                 if (leftHandler)
759                 {
760                         handlerPoint.x = handlerPoint.x - pHandlerBitmap->GetWidth();
761                 }
762         }
763
764         bounds.x = handlerPoint.x;
765         bounds.y = handlerPoint.y;
766         bounds.width = pHandlerBitmap->GetWidth();
767         bounds.height = pHandlerBitmap->GetHeight();
768
769         pCopyPasteHandler->Open(false);
770         pCopyPasteHandler->SetBounds(bounds);
771         pCopyPasteHandler->CheckReverseStatus();
772         pCopyPasteHandler->AdjustBounds();
773
774         return pCopyPasteHandler;
775
776 CATCH:
777         pCopyPasteHandler->Close();
778         delete pCopyPasteHandler;
779
780         return null;
781 }
782
783 _EditCopyPasteHandler*
784 _EditCopyPasteHandler::CreateInstanceN(const FloatPoint& point, int handlerCursorPos, _EditCopyPasteManager* pCopyPasteManager, bool singleHandler, bool leftHandler)
785 {
786         _EditCopyPasteHandler* pCopyPasteHandler = new (std::nothrow) _EditCopyPasteHandler(point, handlerCursorPos, pCopyPasteManager, singleHandler, leftHandler);
787         SysTryReturn(NID_UI_CTRL, pCopyPasteHandler != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
788
789         FloatPoint handlerPoint(point);
790         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
791         Bitmap* pHandlerBitmap = pCopyPasteHandler->GetHandlerBitmap();
792
793         result r = pCopyPasteHandler->CreateRootVisualElement(_WINDOW_TYPE_VE);
794         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
795
796         pCopyPasteHandler->SetActivationEnabled(false);
797
798         if (singleHandler)
799         {
800                 handlerPoint.x = handlerPoint.x - (pHandlerBitmap->GetWidthF() / 2.0f);
801         }
802         else
803         {
804                 if (leftHandler)
805                 {
806                         handlerPoint.x = handlerPoint.x - pHandlerBitmap->GetWidthF();
807                 }
808         }
809
810         bounds.x = handlerPoint.x;
811         bounds.y = handlerPoint.y;
812         bounds.width = pHandlerBitmap->GetWidthF();
813         bounds.height = pHandlerBitmap->GetHeightF();
814
815         pCopyPasteHandler->Open(false);
816         pCopyPasteHandler->SetBounds(bounds);
817         pCopyPasteHandler->CheckReverseStatus();
818         pCopyPasteHandler->AdjustBounds();
819
820         return pCopyPasteHandler;
821
822 CATCH:
823         pCopyPasteHandler->Close();
824         delete pCopyPasteHandler;
825
826         return null;
827 }
828
829 int
830 _EditCopyPasteHandler::GetHandlerCursorPosition(void) const
831 {
832         return __handlerCursorPos;
833 }
834
835 void
836 _EditCopyPasteHandler::SetHandlerRowColumnIndex(int rowIndex, int columnIndex)
837 {
838         __rowIndex = rowIndex;
839         __columnIndex = columnIndex;
840 }
841
842 void
843 _EditCopyPasteHandler::GetHandlerRowColumnIndex(int& rowIndex, int& columnIndex) const
844 {
845         rowIndex = __rowIndex;
846         columnIndex = __columnIndex;
847 }
848
849 void
850 _EditCopyPasteHandler::SetHandlerCursorPosition(int handlerCursorPos)
851 {
852         __handlerCursorPos = handlerCursorPos;
853         __rowIndex = -1;
854         __columnIndex = -1;
855 }
856
857 void
858 _EditCopyPasteHandler::AdjustBounds(void)
859 {
860         FloatRectangle cursorRect;
861         FloatRectangle rect = GetBoundsF();
862         FloatPoint checkPoint(0.0f, 0.0f);
863         _Edit* pEdit = __pCopyPasteManager->GetEdit();
864         _EditPresenter* pEditPresenter = pEdit->GetPresenter();
865
866         if (__singleHandler)
867         {
868                 if (__rowIndex >= 0 && __columnIndex >= 0)
869                 {
870                         pEditPresenter->CalculateAbsoluteCursorBounds(__rowIndex, __columnIndex, cursorRect, false);
871                 }
872                 else
873                 {
874                         pEditPresenter->CalculateAbsoluteCursorBounds(__handlerCursorPos, cursorRect, false);
875                 }
876                 rect.x = cursorRect.x - __pHandlerBitmap->GetWidthF()/2.0f;
877                 rect.y = cursorRect.y + cursorRect.height;
878                 checkPoint = FloatPoint(cursorRect.x , cursorRect.y + cursorRect.height);
879                 if (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)
880                 {
881                         rect.y -= (cursorRect.height + __pHandlerBitmap->GetHeightF());
882                 }
883         }
884         else
885         {
886                 if (__rowIndex >= 0 && __columnIndex >= 0)
887                 {
888                         pEditPresenter->CalculateAbsoluteCursorBounds(__rowIndex, __columnIndex, cursorRect, false);
889                 }
890                 else
891                 {
892                         pEditPresenter->CalculateAbsoluteCursorBounds(__handlerCursorPos, cursorRect, false);
893                 }
894
895                 rect.x = cursorRect.x;
896                 rect.y = cursorRect.y + cursorRect.height;
897
898                 checkPoint = FloatPoint(cursorRect.x, cursorRect.y + cursorRect.height);
899
900                 if (__leftHandler)
901                 {
902                         if (__handlerDirection == HANDLER_DIRECTION_NONE)
903                         {
904                                 rect.x = rect.x - __pHandlerBitmap->GetWidthF();
905                         }
906                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)
907                         {
908                                 rect.x = rect.x - __pHandlerBitmap->GetWidthF();
909                                 rect.y -= (rect.height + cursorRect.height);
910                         }
911                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)
912                         {
913                                 rect.y -= (rect.height + cursorRect.height);
914                         }
915                 }
916                 else
917                 {
918                         if (__handlerDirection == HANDLER_DIRECTION_REVERSE_1)
919                         {
920                                 rect.x = rect.x - __pHandlerBitmap->GetWidthF();
921                         }
922                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)
923                         {
924                                 rect.y -= (rect.height + cursorRect.height);
925                         }
926                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)
927                         {
928                                 rect.x = rect.x - __pHandlerBitmap->GetWidthF();
929                                 rect.y -= (rect.height + cursorRect.height);
930                         }
931                 }
932         }
933
934         if (!__isTouchMoving)
935         {
936                 bool visibleState = __pCopyPasteManager->CheckHandleBounds(checkPoint);
937                 if (visibleState && !GetVisibleState())
938                 {
939                         SetVisibleState(true);
940                         Open();
941                 }
942                 else if (!visibleState && GetVisibleState())
943                 {
944                         SetVisibleState(false);
945                         Close();
946                 }
947         }
948
949         if (__singleHandler && pEditPresenter->IsViewModeEnabled())
950         {
951                 SetVisibleState(false);
952         }
953
954         SetBounds(rect);
955         return;
956 }
957
958 void
959 _EditCopyPasteHandler::OnDraw(void)
960 {
961         Canvas* pCanvas = GetCanvasN();
962         if (pCanvas == null)
963         {
964                 return;
965         }
966         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
967         pCanvas->Clear();
968         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pHandlerBitmap))
969         {
970                 pCanvas->DrawNinePatchedBitmap(pCanvas->GetBoundsF(), *__pHandlerBitmap);
971         }
972         else
973         {
974                 pCanvas->DrawBitmap(pCanvas->GetBoundsF(), *__pHandlerBitmap);
975         }
976
977         delete pCanvas;
978 }
979
980 bool
981 _EditCopyPasteHandler::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
982 {
983         _ContextMenu* pCopyPastePopup = __pCopyPasteManager->GetCopyPastePopup();
984         if (pCopyPastePopup)
985         {
986                 pCopyPastePopup->SetVisibleState(false);
987                 pCopyPastePopup->Close();
988         }
989
990 #if EDIT_COPY_PASTE_MAGNIFIER
991         if (!__pCopyPasteMagnifier)
992         {
993                 CreateCopyPasteMagnifier();
994         }
995         else
996         {
997                 __pCopyPasteMagnifier->SetVisibleState(true);
998                 __pCopyPasteMagnifier->Open();
999         }
1000 #endif
1001         __touchPressedPoint = touchinfo.GetCurrentPosition();
1002         __absoluteTouchPressedPoint = FloatPoint(GetBoundsF().x + __touchPressedPoint.x, GetBoundsF().y + __touchPressedPoint.y);
1003         __isTouchPressed = true;
1004         Invalidate();
1005         return true;
1006 }
1007
1008 void
1009 _EditCopyPasteHandler::CheckReverseStatus(void)
1010 {
1011         FloatDimension screenSize;
1012         _ControlManager* pControlManager = _ControlManager::GetInstance();
1013         _Edit* pEdit = __pCopyPasteManager->GetEdit();
1014         _ControlOrientation orientation = pEdit->GetOrientation();
1015         FloatRectangle rect = GetBoundsF();
1016         FloatRectangle cursorAbsBounds = __pCopyPasteManager->GetCursorBoundsF(true);
1017         float clipboardHeight = 0.0f;
1018         FloatRectangle keypadBounds(0.0f, 0.0f, 0.0f, 0.0f);
1019         float adjustHeight = 0.0f;
1020
1021         _EditPresenter* pEditPresenter = pEdit->GetPresenter();
1022         SysTryReturnVoidResult(NID_UI_CTRL, pEditPresenter, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.\n");
1023
1024         clipboardHeight = pEditPresenter->GetClipboardHeight();
1025         pEditPresenter->GetKeypadBoundsEx(keypadBounds);
1026         if (clipboardHeight > keypadBounds.height)
1027         {
1028                 adjustHeight = clipboardHeight;
1029         }
1030         else
1031         {
1032                 adjustHeight = keypadBounds.height;
1033         }
1034
1035         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1036         {
1037                 screenSize = pControlManager->GetScreenSizeF();
1038         }
1039         else
1040         {
1041                 screenSize.width = pControlManager->GetScreenSizeF().height;
1042                 screenSize.height = pControlManager->GetScreenSizeF().width;
1043         }
1044         if (adjustHeight > 0.0f)
1045         {
1046                 screenSize.height -= adjustHeight;
1047         }
1048
1049         if (__singleHandler)
1050         {
1051                 if ((__handlerDirection == HANDLER_DIRECTION_NONE) && ((cursorAbsBounds.y + cursorAbsBounds.height + rect.height) > screenSize.height))
1052                 {
1053                         __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1054                         rect.y -= (cursorAbsBounds.height + rect.height);
1055                         __reverseCheck = true;
1056                         ChangeHandlerBitmap();
1057                         SetBounds(rect);
1058                 }
1059                 else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((cursorAbsBounds.y + cursorAbsBounds.height + rect.height) <= screenSize.height))
1060                 {
1061                         __handlerDirection = HANDLER_DIRECTION_NONE;
1062                         rect.y += (cursorAbsBounds.height + rect.height);
1063                         __reverseCheck = true;
1064                         ChangeHandlerBitmap();
1065                         SetBounds(rect);
1066                 }
1067                 return;
1068         }
1069
1070         if (__leftHandler)
1071         {
1072                 if (((__handlerDirection == HANDLER_DIRECTION_NONE) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)) && rect.x < 0.0f)
1073                 {
1074                         if ((__handlerDirection == HANDLER_DIRECTION_NONE) && ((rect.y + rect.height) > screenSize.height))
1075                         {
1076                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1077                                 rect.y -= (rect.height + cursorAbsBounds.height);
1078                         }
1079                         else if ((__handlerDirection == HANDLER_DIRECTION_NONE) && ((rect.y + rect.height) <= screenSize.height))
1080                         {
1081                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1082                         }
1083                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((rect.y + 2*rect.height) > screenSize.height))
1084                         {
1085                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1086                         }
1087                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((rect.y + 2*rect.height) <= screenSize.height))
1088                         {
1089                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1090                                 rect.y += (rect.height + cursorAbsBounds.height);
1091                         }
1092                         ChangeHandlerBitmap();
1093                         rect.x += rect.width;
1094                         __reverseCheck = true;
1095                 }
1096                 else if (((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)) && rect.x >= rect.width)
1097                 {
1098                         if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && ((rect.y + rect.height) > screenSize.height))
1099                         {
1100                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1101                                 rect.y -= (rect.height + cursorAbsBounds.height);
1102                         }
1103                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && ((rect.y + rect.height) <= screenSize.height))
1104                         {
1105                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1106                         }
1107                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.y + 2*rect.height) > screenSize.height))
1108                         {
1109                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1110                         }
1111                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.y + 2*rect.height) <= screenSize.height))
1112                         {
1113                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1114                                 rect.y += (rect.height + cursorAbsBounds.height);
1115                         }
1116                         ChangeHandlerBitmap();
1117                         rect.x -= rect.width;
1118                         __reverseCheck = true;
1119                 }
1120                 else if (((__handlerDirection == HANDLER_DIRECTION_NONE) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_1)) && ((rect.y + rect.height) > screenSize.height))
1121                 {
1122                         if ((__handlerDirection == HANDLER_DIRECTION_NONE) && rect.x < rect.width)
1123                         {
1124                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1125                                 rect.x += rect.width;
1126                         }
1127                         else if ((__handlerDirection == HANDLER_DIRECTION_NONE) && rect.x >= rect.width)
1128                         {
1129                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1130                         }
1131                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && ((rect.x - rect.width) >= 0.0f))
1132                         {
1133                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1134                                 rect.x -= rect.width;
1135                         }
1136                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && ((rect.x - rect.width) < 0.0f))
1137                         {
1138                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1139                         }
1140                         rect.y -= (rect.height + cursorAbsBounds.height);
1141                         ChangeHandlerBitmap();
1142                         __reverseCheck = true;
1143                 }
1144                 else if (((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)) && ((rect.y + 2*rect.height + cursorAbsBounds.height) <= screenSize.height))
1145                 {
1146                         if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && rect.x < 0.0f)
1147                         {
1148                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1149                                 rect.x += rect.width;
1150                         }
1151                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && rect.x >= rect.width)
1152                         {
1153                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1154                         }
1155                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.x - rect.width) >= 0.0f))
1156                         {
1157                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1158                                 rect.x -= rect.width;
1159                         }
1160                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.x - rect.width) < 0.0f))
1161                         {
1162                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1163                         }
1164                         rect.y += (rect.height + cursorAbsBounds.height);
1165                         ChangeHandlerBitmap();
1166                         __reverseCheck = true;
1167                 }
1168         }
1169         else
1170         {
1171                 if (((__handlerDirection == HANDLER_DIRECTION_NONE) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)) && (rect.x + rect.width) > screenSize.width)
1172                 {
1173                         if ((__handlerDirection == HANDLER_DIRECTION_NONE) && ((rect.y + rect.height) > screenSize.height))
1174                         {
1175                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1176                                 rect.y -= (rect.height + cursorAbsBounds.height);
1177                         }
1178                         else if ((__handlerDirection == HANDLER_DIRECTION_NONE) && ((rect.y + rect.height) <= screenSize.height))
1179                         {
1180                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1181                         }
1182                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((rect.y + 2*rect.height) > screenSize.height))
1183                         {
1184                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1185                         }
1186                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((rect.y + 2*rect.height) <= screenSize.height))
1187                         {
1188                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1189                                 rect.y += (rect.height + cursorAbsBounds.height);
1190                         }
1191                         ChangeHandlerBitmap();
1192                         rect.x -= rect.width;
1193                         __reverseCheck = true;
1194                 }
1195                 else if (((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)) && (rect.x + 2*rect.width) <= screenSize.width)
1196                 {
1197                         if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && ((rect.y + rect.height) > screenSize.height))
1198                         {
1199                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1200                                 rect.y -= (rect.height + cursorAbsBounds.height);
1201                         }
1202                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && ((rect.y + rect.height) <= screenSize.height))
1203                         {
1204                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1205                         }
1206                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.y + 2*rect.height) > screenSize.height))
1207                         {
1208                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1209                         }
1210                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.y + 2*rect.height) <= screenSize.height))
1211                         {
1212                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1213                                 rect.y += (rect.height + cursorAbsBounds.height);
1214                         }
1215                         ChangeHandlerBitmap();
1216                         rect.x += rect.width;
1217                         __reverseCheck = true;
1218                 }
1219                 else if (((__handlerDirection == HANDLER_DIRECTION_NONE) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_1)) && ((rect.y + rect.height) > screenSize.height))
1220                 {
1221                         if ((__handlerDirection == HANDLER_DIRECTION_NONE) && (rect.x + rect.width) > screenSize.width)
1222                         {
1223                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1224                                 rect.x -= rect.width;
1225                         }
1226                         else if ((__handlerDirection == HANDLER_DIRECTION_NONE) && (rect.x + rect.width) <= screenSize.width)
1227                         {
1228                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1229                         }
1230                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && (rect.x + 2*rect.width) <= screenSize.width)
1231                         {
1232                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_2;
1233                                 rect.x += rect.width;
1234                         }
1235                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_1) && (rect.x + 2*rect.width) > screenSize.width)
1236                         {
1237                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_3;
1238                         }
1239                         rect.y -= (rect.height + cursorAbsBounds.height);
1240                         ChangeHandlerBitmap();
1241                         __reverseCheck = true;
1242                 }
1243                 else if (((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) || (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)) && ((rect.y + 2*rect.height + cursorAbsBounds.height) <= screenSize.height))
1244                 {
1245                         if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((rect.x + rect.width) <= screenSize.width))
1246                         {
1247                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1248                         }
1249                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_2) && ((rect.x + rect.width) > screenSize.width))
1250                         {
1251                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1252                                 rect.x -= rect.width;
1253                         }
1254                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.x + 2*rect.width) <= screenSize.width))
1255                         {
1256                                 __handlerDirection = HANDLER_DIRECTION_NONE;
1257                                 rect.x += rect.width;
1258                         }
1259                         else if ((__handlerDirection == HANDLER_DIRECTION_REVERSE_3) && ((rect.x + 2*rect.width) > screenSize.width))
1260                         {
1261                                 __handlerDirection = HANDLER_DIRECTION_REVERSE_1;
1262                         }
1263                         rect.y += (rect.height + cursorAbsBounds.height);
1264                         ChangeHandlerBitmap();
1265                         __reverseCheck = true;
1266                 }
1267         }
1268
1269         SetBounds(rect);
1270 }
1271
1272 bool
1273 _EditCopyPasteHandler::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1274 {
1275         CheckReverseStatus();
1276         __isTouchPressed = false;
1277         __absoluteTouchPressedPoint = FloatPoint(0.0f, 0.0f);
1278         if (__pCopyPasteMagnifier)
1279         {
1280                 __pCopyPasteMagnifier->SetVisibleState(false);
1281                 __pCopyPasteMagnifier->Close();
1282         }
1283         _ContextMenu* pCopyPastePopup = __pCopyPasteManager->GetCopyPastePopup();
1284         if (pCopyPastePopup && !__isTouchMoving)
1285         {
1286                 pCopyPastePopup->SetVisibleState(true);
1287                 pCopyPastePopup->Open();
1288         }
1289         else
1290         {
1291                 __pCopyPasteManager->CreateCopyPastePopup();
1292         }
1293         __pCopyPasteManager->Show();
1294         __pCopyPasteManager->SendTextBlockEvent();
1295         Invalidate();
1296         __isTouchMoving = false;
1297
1298         if (!__singleHandler)
1299         {
1300                 int leftRowIndex = -1;
1301                 int leftColumnIndex = -1;
1302                 int rightRowIndex = -1;
1303                 int rightColumnIndex = -1;
1304                 int leftHandlerCursorPos = -1;
1305                 int rightHandlerCursorPos = -1;
1306
1307                 __pCopyPasteManager->GetHandlerRowColumnIndex(false, true, leftRowIndex, leftColumnIndex);
1308                 __pCopyPasteManager->GetHandlerRowColumnIndex(false, false, rightRowIndex, rightColumnIndex);
1309                 leftHandlerCursorPos = __pCopyPasteManager->GetHandlerCursorPosition(_EditCopyPasteManager::HANDLER_TYPE_LEFT);
1310                 rightHandlerCursorPos = __pCopyPasteManager->GetHandlerCursorPosition(_EditCopyPasteManager::HANDLER_TYPE_RIGHT);
1311
1312                 _ContextMenu* pCopyPastePopup = __pCopyPasteManager->GetCopyPastePopup();
1313
1314                 if(__leftHandler && __handlerCursorPos > rightHandlerCursorPos)
1315                 {
1316                         __pCopyPasteManager->CreateHandle(rightHandlerCursorPos, leftHandlerCursorPos, rightRowIndex, rightColumnIndex, leftRowIndex, leftColumnIndex);
1317
1318                         if (pCopyPastePopup)
1319                         {
1320                                 pCopyPastePopup->ReleaseTouchCapture();
1321                         }
1322                 }
1323                 else if (!__leftHandler && __handlerCursorPos < leftHandlerCursorPos)
1324                 {
1325                         __pCopyPasteManager->CreateHandle(rightHandlerCursorPos, leftHandlerCursorPos, rightRowIndex, rightColumnIndex, leftRowIndex, leftColumnIndex);
1326                         if (pCopyPastePopup)
1327                         {
1328                                 pCopyPastePopup->ReleaseTouchCapture();
1329                         }
1330                 }
1331         }
1332         return true;
1333 }
1334
1335 bool
1336 _EditCopyPasteHandler::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1337 {
1338         int cursorPos = -1;
1339         FloatRectangle cursorRect(0.0f, 0.0f, 0.0f, 0.0f);
1340         FloatRectangle absCursorRect(0.0f, 0.0f, 0.0f, 0.0f);
1341         FloatRectangle rect = GetBoundsF();
1342         FloatPoint point = touchinfo.GetCurrentPosition();
1343         FloatPoint touchPoint(0.0f, 0.0f);
1344         FloatPoint checkPoint(0.0f, 0.0f);
1345         __isTouchMoving = true;
1346
1347         _Edit* pEdit = __pCopyPasteManager->GetEdit();
1348         SysTryReturn(NID_UI_CTRL, pEdit, false, E_INVALID_STATE, "[E_INVALID_STATE] pEdit is null.\n");
1349
1350         _EditPresenter* pEditPresenter = pEdit->GetPresenter();
1351         SysTryReturn(NID_UI_CTRL, pEditPresenter, false, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.\n");
1352
1353         TextObject* pTextObject = pEditPresenter->GetTextObject();
1354         SysTryReturn(NID_UI_CTRL, pTextObject, false, E_INVALID_STATE, "[E_INVALID_STATE] pEditPresenter is null.\n");
1355
1356         int curCursorLine = pTextObject->GetLineIndexAtTextIndex(__handlerCursorPos);
1357         int totalLine = pTextObject->GetTotalLineCount();
1358
1359         float totalHeight = pTextObject->GetTotalHeightF();
1360         float firstDisplayY = pTextObject->GetFirstDisplayPositionYF();
1361         FloatRectangle absTextObjectBounds(0.0f, 0.0f, 0.0f, 0.0f);
1362         FloatRectangle textObjectBounds = pEditPresenter->GetTextBoundsF();
1363         FloatRectangle absEditBounds = pEdit->GetAbsoluteBoundsF(true);
1364         absTextObjectBounds.x = absEditBounds.x + textObjectBounds.x;
1365         absTextObjectBounds.y = absEditBounds.y + textObjectBounds.y;
1366         absTextObjectBounds.width = textObjectBounds.width;
1367         absTextObjectBounds.height  = textObjectBounds.height;
1368         if (__touchPressedPoint.x == point.x && __touchPressedPoint.y == point.y)
1369         {
1370                 return true;
1371         }
1372
1373         if (__rowIndex >= 0 && __columnIndex >= 0)
1374         {
1375                 pEditPresenter->CalculateCursorBounds(pEditPresenter->GetTextBoundsF(), cursorRect, __rowIndex, __columnIndex);
1376                 pEditPresenter->CalculateAbsoluteCursorBounds(__rowIndex, __columnIndex, absCursorRect);
1377         }
1378         else
1379         {
1380                 pEditPresenter->CalculateCursorBounds(pEditPresenter->GetTextBoundsF(), cursorRect,__handlerCursorPos);
1381                 pEditPresenter->CalculateAbsoluteCursorBounds(__handlerCursorPos, absCursorRect);
1382         }
1383
1384         FloatPoint absoluteTouchMovedPoint = FloatPoint(GetBoundsF().x + point.x, GetBoundsF().y + point.y);
1385         //Calculate handler's position
1386         if (__singleHandler)
1387         {
1388                 touchPoint.x = absoluteTouchMovedPoint.x;
1389                 if (__handlerDirection == HANDLER_DIRECTION_NONE)
1390                 {
1391                         touchPoint.y = absoluteTouchMovedPoint.y - GetBoundsF().height/2.0f;
1392                 }
1393                 else // HANDLER_DIRECTION_REVERSE_2
1394                 {
1395                         touchPoint.y = absoluteTouchMovedPoint.y + GetBoundsF().height/2.0f;
1396                 }
1397         }
1398         else
1399         {
1400                 if (__leftHandler)
1401                 {
1402                         if (__handlerDirection == HANDLER_DIRECTION_NONE)
1403                         {
1404                                 touchPoint.x = absoluteTouchMovedPoint.x + GetBoundsF().width/2.0f;
1405                                 touchPoint.y = absoluteTouchMovedPoint.y - GetBoundsF().height/2.0f;
1406                         }
1407                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_1)
1408                         {
1409                                 touchPoint.x = absoluteTouchMovedPoint.x - GetBoundsF().width/2.0f;
1410                                 touchPoint.y = absoluteTouchMovedPoint.y - GetBoundsF().height/2.0f;
1411                         }
1412                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)
1413                         {
1414                                 touchPoint.x = absoluteTouchMovedPoint.x + GetBoundsF().width/2.0f;
1415                                 touchPoint.y = absoluteTouchMovedPoint.y + GetBoundsF().height/2.0f;
1416                         }
1417                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)
1418                         {
1419                                 touchPoint.x = absoluteTouchMovedPoint.x - GetBoundsF().width/2.0f;
1420                                 touchPoint.y = absoluteTouchMovedPoint.y + GetBoundsF().height/2.0f;
1421                         }
1422                 }
1423                 else
1424                 {
1425                         if (__handlerDirection == HANDLER_DIRECTION_NONE)
1426                         {
1427                                 touchPoint.x = absoluteTouchMovedPoint.x - GetBoundsF().width/2.0f;
1428                                 touchPoint.y = absoluteTouchMovedPoint.y - GetBoundsF().height/2.0f;
1429                         }
1430                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_1)
1431                         {
1432                                 touchPoint.x = absoluteTouchMovedPoint.x + GetBoundsF().width/2.0f;
1433                                 touchPoint.y = absoluteTouchMovedPoint.y - GetBoundsF().height/2.0f;
1434                         }
1435                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_2)
1436                         {
1437                                 touchPoint.x = absoluteTouchMovedPoint.x - GetBoundsF().width/2.0f;
1438                                 touchPoint.y = absoluteTouchMovedPoint.y + GetBoundsF().height/2.0f;
1439                         }
1440                         else if (__handlerDirection == HANDLER_DIRECTION_REVERSE_3)
1441                         {
1442                                 touchPoint.x = absoluteTouchMovedPoint.x + GetBoundsF().width/2.0f;
1443                                 touchPoint.y = absoluteTouchMovedPoint.y + GetBoundsF().height/2.0f;
1444                         }
1445                 }
1446         }
1447         if (totalHeight - firstDisplayY < absTextObjectBounds.height)
1448         {
1449                 absTextObjectBounds.height = totalHeight - firstDisplayY - 1.0f; // check TextObject
1450         }
1451
1452         if (totalLine != 1) //single line edit doesn't need to adjust horizontal value.
1453         {
1454                 if (absTextObjectBounds.x > touchPoint.x)
1455                 {
1456                         touchPoint.x = absTextObjectBounds.x;
1457                 }
1458                 if (absTextObjectBounds.x + absTextObjectBounds.width <= touchPoint.x) // check FloatRectangle Contains?
1459                 {
1460                         touchPoint.x = absTextObjectBounds.x + absTextObjectBounds.width - 1.0f;
1461                 }
1462         }
1463         if (absTextObjectBounds.y > touchPoint.y)
1464         {
1465                 if (totalLine == 1 || firstDisplayY == 0.0f) // whether need to scroll the text or not
1466                 {
1467                         touchPoint.y = absTextObjectBounds.y; //not need to scroll the text.
1468                 }
1469         }
1470         if (absTextObjectBounds.y + absTextObjectBounds.height < touchPoint.y)
1471         {
1472                 if (totalLine == 1 || (totalHeight - firstDisplayY < textObjectBounds.height) || curCursorLine == (totalLine - 1)) // || pTextObject->IsDisplayedLastLine()) // whether need to scroll the text or not
1473                 {
1474                         touchPoint.y = absTextObjectBounds.y + absTextObjectBounds.height - 1.0f; // check TextObject
1475                 }
1476         }
1477
1478         touchPoint.x = touchPoint.x - absEditBounds.x - textObjectBounds.x;
1479         touchPoint.y = touchPoint.y - absEditBounds.y - textObjectBounds.y;
1480
1481         if (Math::Abs(touchPoint.y) < 1)
1482         {
1483                 touchPoint.y = 0.0f;
1484         }
1485
1486         int rowIndex = -1;
1487         int columnIndex = -1;
1488         cursorPos = pTextObject->GetTextIndexFromPosition(touchPoint.x, touchPoint.y, rowIndex, columnIndex, true);
1489
1490         if (__handlerCursorPos == cursorPos)
1491         {
1492                 return true;
1493         }
1494
1495         if (cursorPos == -1)
1496         {
1497                 //To get cursorPos
1498                 if (totalLine != 1)
1499                 {
1500                         if (absoluteTouchMovedPoint.y > (absCursorRect.y + absCursorRect.height))
1501                         {
1502                                 if (curCursorLine < totalLine - 1)
1503                                 {
1504                                         int offset = __handlerCursorPos - pTextObject->GetFirstTextIndexAt(curCursorLine);
1505                                         int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine+1);
1506                                         cursorPos = offset + firstTextIndex;
1507                                         int textLength = pTextObject->GetTextLengthAt(curCursorLine+1);
1508                                         if (offset > textLength)
1509                                         {
1510                                                 cursorPos = firstTextIndex+textLength;
1511                                         }
1512                                 }
1513                         }
1514                         else
1515                         {
1516                                 if (curCursorLine !=0)
1517                                 {
1518                                         if (__rowIndex == 0)
1519                                         {
1520                                                 return true;
1521                                         }
1522                                         int offset = __handlerCursorPos - pTextObject->GetFirstTextIndexAt(curCursorLine);
1523                                         int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine-1);
1524                                         cursorPos = offset + firstTextIndex;
1525                                         int textLength = pTextObject->GetTextLengthAt(curCursorLine-1);
1526                                         if (offset > textLength)
1527                                         {
1528                                                 cursorPos = firstTextIndex+textLength;
1529                                         }
1530                                 }
1531                         }
1532                 }
1533                 if (cursorPos == -1)
1534                 {
1535                         return true;
1536                 }
1537         }
1538
1539         if (__handlerCursorPos == cursorPos)
1540         {
1541                 return true;
1542         }
1543
1544         if (!__singleHandler)
1545         {
1546                 _EditCopyPasteManager::HandlerType nextHandlerType = _EditCopyPasteManager::HANDLER_TYPE_MAX;
1547                 if (__leftHandler)
1548                 {
1549                         nextHandlerType = _EditCopyPasteManager::HANDLER_TYPE_RIGHT;
1550                 }
1551                 else
1552                 {
1553                         nextHandlerType = _EditCopyPasteManager::HANDLER_TYPE_LEFT;
1554                 }
1555                 int nextHandler = __pCopyPasteManager->GetHandlerCursorPosition(nextHandlerType);
1556                 if (totalLine == 1 && (nextHandler == 0 || nextHandler == pEditPresenter->GetTextLength()))
1557                 {
1558                         if (Math::Abs(nextHandler - cursorPos) == 1)
1559                         {
1560                                 pTextObject->SetFirstDisplayLineIndexFromTextIndex(nextHandler);
1561                         }
1562                 }
1563                 if (nextHandler == cursorPos)
1564                 {
1565                         return true;
1566                 }
1567         }
1568
1569         if (rowIndex > -1 && columnIndex > -1)
1570         {
1571                 __rowIndex = rowIndex;
1572                 __columnIndex =  columnIndex;
1573         }
1574         else
1575         {
1576                 __rowIndex = -1;
1577                 __columnIndex  = -1;
1578         }
1579
1580         pTextObject->SetFirstDisplayLineIndexFromTextIndex(cursorPos);
1581
1582         __handlerCursorPos = cursorPos;
1583
1584         if (__rowIndex >= 0 && __columnIndex >= 0)
1585         {
1586                 pEditPresenter->SetCursorPosition(cursorPos, __rowIndex, __columnIndex);
1587         }
1588         else
1589         {
1590                 __pCopyPasteManager->SetCursorPosition(cursorPos);
1591         }
1592
1593         pEditPresenter->ScrollPanelToCursorPosition(true);
1594
1595         if (!__singleHandler)
1596         {
1597                 __pCopyPasteManager->RefreshBlock(__leftHandler);
1598         }
1599         else
1600         {
1601                 pEditPresenter->DrawText();
1602                 AdjustBounds();
1603         }
1604         CheckReverseStatus();
1605         Invalidate();
1606         MoveCopyPasteMagnifier();
1607
1608         return true;
1609 }
1610
1611 bool
1612 _EditCopyPasteHandler::IsActivatedOnOpen(void) const
1613 {
1614         return false;
1615 }
1616
1617 void
1618 _EditCopyPasteHandler::OnChangeLayout(_ControlOrientation orientation)
1619 {
1620         AdjustBounds();
1621         return;
1622 }
1623
1624 result
1625 _EditCopyPasteHandler::OnAttachedToMainTree(void)
1626 {
1627         result r = E_SUCCESS;
1628
1629         if (GetOwner() == null)
1630         {
1631                 _Edit* pEdit = __pCopyPasteManager->GetEdit();
1632                 SysTryReturnResult(NID_UI_CTRL, pEdit, GetLastResult(), "Unable to get pEdit.");
1633
1634                 _Window* pWindow = null;
1635                 _Control* pControlCore = null;
1636
1637                 for (pControlCore = pEdit->GetParent(); pWindow == null; pControlCore = pControlCore->GetParent())
1638                 {
1639                         if (pControlCore == null)
1640                         {
1641                                 break;
1642                         }
1643
1644                         pWindow = dynamic_cast<_Window*>(pControlCore);
1645                         if (pWindow)
1646                         {
1647                                 SetOwner(pWindow);
1648                                 return r;
1649                         }
1650                 }
1651
1652                 _EditPresenter* pEditPresenter = pEdit->GetPresenter();
1653                 SysTryReturnResult(NID_UI_CTRL, pEdit, GetLastResult(), "Unable to get pEditPresenter.");
1654
1655                 _Form* pParentForm = pEditPresenter->GetParentForm();
1656                 if (pParentForm)
1657                 {
1658                         SetOwner(pParentForm);
1659                 }
1660                 else
1661                 {
1662                         _Form* pForm = null;
1663                         _Frame* pCurrentFrame = dynamic_cast <_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
1664                         if (pCurrentFrame)
1665                         {
1666                                 pForm = pCurrentFrame->GetCurrentForm();
1667                                 if (pForm)
1668                                 {
1669                                         SetOwner(pForm);
1670                                 }
1671                                 else
1672                                 {
1673                                         SetOwner(pCurrentFrame);
1674                                 }
1675                         }
1676                 }
1677         }
1678
1679         return r;
1680 }
1681
1682 _EditCopyPasteManager::_EditCopyPasteManager(_Edit& parenEdit)
1683         : __pCopyPastePopup(null)
1684         , __contextMenuAlign(CONTEXT_MENU_CORE_ALIGN_UP)
1685         , __pCoreCopyPasteEvent(null)
1686         , __pEdit(&parenEdit)
1687         , __pEditPresenter(null)
1688         , __contextMenuHeight(0.0f)
1689         , __needToReleaseBlock(true)
1690         , __isHandlerMoving(false)
1691         , __editVisibleArea(0.0f, 0.0f, 0.0f, 0.0f)
1692 {
1693         __pEditPresenter = __pEdit->GetPresenter();
1694         __pHandle[HANDLER_TYPE_CENTER] = null;
1695         __pHandle[HANDLER_TYPE_LEFT] = null;
1696         __pHandle[HANDLER_TYPE_RIGHT] = null;
1697
1698                 CreateHandle();
1699 }
1700
1701 _EditCopyPasteManager::~_EditCopyPasteManager(void)
1702 {
1703         ReleaseCopyPastePopup();
1704         ReleaseHandle();
1705
1706         if (__pCoreCopyPasteEvent)
1707         {
1708                 delete __pCoreCopyPasteEvent;
1709                 __pCoreCopyPasteEvent = null;
1710         }
1711 }
1712
1713 void
1714 _EditCopyPasteManager::ReleaseHandle(void)
1715 {
1716         if (__pHandle[HANDLER_TYPE_CENTER])
1717         {
1718                 __pHandle[HANDLER_TYPE_CENTER]->Close();
1719                 delete __pHandle[HANDLER_TYPE_CENTER];
1720                 __pHandle[HANDLER_TYPE_CENTER] = null;
1721         }
1722
1723         if (__pHandle[HANDLER_TYPE_LEFT])
1724         {
1725                 __pHandle[HANDLER_TYPE_LEFT]->Close();
1726                 delete __pHandle[HANDLER_TYPE_LEFT];
1727                 __pHandle[HANDLER_TYPE_LEFT] = null;
1728         }
1729
1730         if (__pHandle[HANDLER_TYPE_RIGHT])
1731         {
1732                 __pHandle[HANDLER_TYPE_RIGHT]->Close();
1733                 delete __pHandle[HANDLER_TYPE_RIGHT];
1734                 __pHandle[HANDLER_TYPE_RIGHT] = null;
1735         }
1736 }
1737
1738 void
1739 _EditCopyPasteManager::ReleaseCopyPastePopup(void)
1740 {
1741         if (__pCopyPastePopup)
1742         {
1743                 __pCopyPastePopup->Close();
1744                 delete __pCopyPastePopup;
1745                 __pCopyPastePopup = null;
1746         }
1747 }
1748
1749 bool
1750 _EditCopyPasteManager::IsCopyPastePopup(const _Control& control) const
1751 {
1752         if (__pCopyPastePopup == &control)
1753         {
1754                 return true;
1755         }
1756
1757         return false;
1758 }
1759
1760 bool
1761 _EditCopyPasteManager::IsCopyPasteHandle(const _Control& control) const
1762 {
1763         if (__pHandle[HANDLER_TYPE_CENTER] == &control)
1764         {
1765                 return true;
1766         }
1767
1768         if (__pHandle[HANDLER_TYPE_LEFT] == &control)
1769         {
1770                 return true;
1771         }
1772
1773         if (__pHandle[HANDLER_TYPE_RIGHT] == &control)
1774         {
1775                 return true;
1776         }
1777
1778         return false;
1779 }
1780
1781 result
1782 _EditCopyPasteManager::AddCopyPasteEventListener(const _IEditCopyPasteEventListener& listener)
1783 {
1784         ClearLastResult();
1785
1786         if (__pCoreCopyPasteEvent == null)
1787         {
1788                 __pCoreCopyPasteEvent = _EditCopyPasteEvent::CreateInstanceN(*this);
1789                 SysTryReturn(NID_UI_CTRL, __pCoreCopyPasteEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.\n");
1790         }
1791
1792         return __pCoreCopyPasteEvent->AddListener(listener);
1793 }
1794
1795 result
1796 _EditCopyPasteManager::SendCopyPasteEvent(CoreCopyPasteStatus status, CoreCopyPasteAction action)
1797 {
1798         if (__pCoreCopyPasteEvent)
1799         {
1800                 IEventArg* pCopyPasteEventArg = _EditCopyPasteEvent::CreateCopyPasteEventArgN(status, action);
1801                 SysTryReturn(NID_UI_CTRL, pCopyPasteEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1802
1803                 __pCoreCopyPasteEvent->Fire(*pCopyPasteEventArg);
1804         }
1805
1806         return E_SUCCESS;
1807 }
1808
1809 void
1810 _EditCopyPasteManager::CreateCopyPastePopup(void)
1811 {
1812         if (__pHandle[HANDLER_TYPE_CENTER])
1813         {
1814                 __pHandle[HANDLER_TYPE_CENTER]->DestroyCopyPasteMagnifier();
1815         }
1816         if (__pCopyPastePopup)
1817         {
1818                 __pCopyPastePopup->Close();
1819                 delete __pCopyPastePopup;
1820                 __pCopyPastePopup = null;
1821         }
1822
1823         FloatRectangle startRect;
1824         FloatRectangle endRect;
1825         FloatRectangle editAbsRect;
1826         FloatRectangle editShowAreaAbsRect;
1827         FloatRectangle commandButtonBounds;
1828         FloatRectangle keypadBounds(0.0f, 0.0f, 0.0f, 0.0f);
1829         FloatRectangle formClientBounds(0.0f, 0.0f, 0.0f, 0.0f);
1830         FloatRectangle panelAbsoulteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1831         bool commandButtonExist = false;
1832         bool formExist = false;
1833         bool panelExist = false;
1834         FloatRectangle cursorRect = GetCursorBoundsF(true);
1835
1836         float contextMenuHeight = 0.0f;
1837         float contextMenuTopMargin = 0.0f;
1838         float contextMenuBottomMargin = 0.0f;
1839         float contextMenuArrowHeight = 0.0f;
1840         float handlerHeight = 0.0f;
1841         bool isPasswordStyle = false;
1842         bool isClipped = false;
1843         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
1844         {
1845                 isPasswordStyle = true;
1846         }
1847
1848         _ControlOrientation orientation = __pEdit->GetOrientation();
1849
1850         FloatDimension screenSize;
1851         _ControlManager* pControlManager = _ControlManager::GetInstance();
1852         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1853         {
1854                 screenSize = pControlManager->GetScreenSizeF();
1855         }
1856         else
1857         {
1858                 screenSize.width = pControlManager->GetScreenSizeF().height;
1859                 screenSize.height = pControlManager->GetScreenSizeF().width;
1860         }
1861
1862         GET_SHAPE_CONFIG(EDIT::COPYPASTE_HANDLER_HEIGHT, orientation, handlerHeight);
1863         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ITEM_HEIGHT, orientation, contextMenuHeight);
1864         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_TOP_MARGIN, orientation, contextMenuTopMargin);
1865         GET_SHAPE_CONFIG(CONTEXTMENU::GRID_BOTTOM_MARGIN, orientation, contextMenuBottomMargin);
1866         GET_SHAPE_CONFIG(CONTEXTMENU::ANCHOR_HEIGHT, orientation, contextMenuArrowHeight);
1867
1868         isClipped = __pEdit->IsClipped();
1869         if ((__pEdit->GetTextLength() == 0 || __pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD) && !isClipped)
1870         {
1871                 return;
1872         }
1873
1874         if (__pEdit->GetTextLength() == 0 && (__pEditPresenter->IsViewModeEnabled()))
1875         {
1876                 return;
1877         }
1878
1879         __contextMenuHeight = contextMenuHeight + contextMenuTopMargin + contextMenuBottomMargin + contextMenuArrowHeight;
1880         if (isClipped && __pEditPresenter->IsViewModeEnabled() == false && __pEdit->GetTextLength() > 0 && orientation == _CONTROL_ORIENTATION_PORTRAIT)
1881         {
1882                 __contextMenuHeight = __contextMenuHeight + contextMenuHeight;
1883         }
1884
1885         editAbsRect = __pEdit->GetAbsoluteBoundsF(true);
1886
1887         _Toolbar* pCommandButton = __pEditPresenter->GetKeypadCommandButton();
1888         if (pCommandButton)
1889         {
1890                 commandButtonBounds = pCommandButton->GetAbsoluteBoundsF(true);
1891                 commandButtonExist = true;
1892         }
1893         _Form* pForm = __pEditPresenter->GetParentForm();
1894         if (pForm)
1895         {
1896                 formClientBounds = pForm->GetClientBoundsF();
1897                 formExist = true;
1898         }
1899         _ScrollPanel* pPanel = __pEditPresenter->GetParentPanel();
1900         if (pPanel)
1901         {
1902                 panelAbsoulteBounds = pPanel->GetAbsoluteBoundsF(true);
1903                 panelExist = true;
1904         }
1905         __pEdit->GetKeypadBounds(keypadBounds);
1906
1907         // Edit Show Area
1908         {
1909                 editShowAreaAbsRect = editAbsRect;
1910                 FloatRectangle textObjectBounds = __pEditPresenter->GetTextBoundsF();
1911
1912                 if (!(__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN))
1913                 {
1914                         editShowAreaAbsRect.x += textObjectBounds.x;
1915                         editShowAreaAbsRect.y += textObjectBounds.y;
1916                         editShowAreaAbsRect.width = textObjectBounds.width;
1917
1918                         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE))
1919                         {
1920                                 editShowAreaAbsRect.height = textObjectBounds.height;
1921                         }
1922                 }
1923                 if (editShowAreaAbsRect.y < 0.0f)
1924                 {
1925                         editShowAreaAbsRect.height += editShowAreaAbsRect.y;
1926                         editShowAreaAbsRect.y = 0.0f;
1927                 }
1928
1929                 if (commandButtonExist)
1930                 {
1931                         if (editShowAreaAbsRect.y + editShowAreaAbsRect.height > commandButtonBounds.y)
1932                         {
1933                                 editShowAreaAbsRect.height -= (editShowAreaAbsRect.y + editShowAreaAbsRect.height - commandButtonBounds.y);
1934                         }
1935                 }
1936                 else
1937                 {
1938                         if (editShowAreaAbsRect.y + editShowAreaAbsRect.height > keypadBounds.y)
1939                         {
1940                                 editShowAreaAbsRect.height -= (editShowAreaAbsRect.y + editShowAreaAbsRect.height - keypadBounds.y);
1941                         }
1942                 }
1943                 if (formExist)
1944                 {
1945                         if (editShowAreaAbsRect.y < formClientBounds.y)
1946                         {
1947                                 editShowAreaAbsRect.y = formClientBounds.y;
1948                                 editShowAreaAbsRect.height -= formClientBounds.y;
1949                         }
1950                 }
1951                 if (panelExist)
1952                 {
1953                         if (editShowAreaAbsRect.y < panelAbsoulteBounds.y)
1954                         {
1955                                 editShowAreaAbsRect.height -= (panelAbsoulteBounds.y - editShowAreaAbsRect.y);
1956                                 editShowAreaAbsRect.y = panelAbsoulteBounds.y;
1957                         }
1958                 }
1959                 __editVisibleArea = CoordinateSystem::AlignToDevice(editShowAreaAbsRect);
1960         }
1961         FloatPoint copyPastePoint(0.0f, 0.0f);
1962         __contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_UP;
1963
1964         if (__pEdit->IsBlocked())
1965         {
1966                 int start = -1;
1967                 int end = -1;
1968                 __pEdit->GetBlockRange(start, end);
1969                 if (start == -1 || end == -1)
1970                 {
1971                         SysLog(NID_UI_CTRL, "[EditCopyPasteManager] There is no blocked Range");
1972                         return;
1973                 }
1974
1975                 __pEdit->CalculateAbsoluteCursorBounds(start, startRect);
1976                 __pEdit->CalculateAbsoluteCursorBounds(end, endRect);
1977                 if (startRect.x > endRect.x)
1978                 {
1979                         copyPastePoint.x = endRect.x + (startRect.x - endRect.x)/2;
1980                 }
1981                 else if (startRect.x < endRect.x)
1982                 {
1983                         copyPastePoint.x = startRect.x + (endRect.x - startRect.x)/2;
1984                 }
1985                 else
1986                 {
1987                         copyPastePoint.x = startRect.x;
1988                 }
1989
1990                 if (copyPastePoint.x < editShowAreaAbsRect.x)
1991                 {
1992                         copyPastePoint.x = editShowAreaAbsRect.x;
1993                 }
1994                 else if (copyPastePoint.x > (editShowAreaAbsRect.x + editShowAreaAbsRect.width))
1995                 {
1996                         copyPastePoint.x = editShowAreaAbsRect.x + editShowAreaAbsRect.width;
1997                 }
1998
1999                 //Both of handlers are located on the top of the Editor.
2000                 if ( ((startRect.y + startRect.height) < editShowAreaAbsRect.y) && ((endRect.y + endRect.height) < editShowAreaAbsRect.y))
2001                 {
2002                         SysLog(NID_UI_CTRL, "Both of handlers are located on the top of the Editor.\n");
2003                         return;
2004                 }
2005                 //Both of handlers are located on the bottom of the Editor.
2006                 else if( ((startRect.y + startRect.height) > editShowAreaAbsRect.y + editShowAreaAbsRect.height ) && ((endRect.y + endRect.height) > editShowAreaAbsRect.y + editShowAreaAbsRect.height))
2007                 {
2008                         SysLog(NID_UI_CTRL, "Both of handlers are located on the bottom of the Editor.\n");
2009                         return;
2010                 }
2011                 // Left handler is located on the top of the Editor and Right handler is located on the bottom of the Editor.
2012                 else if ( ((startRect.y + startRect.height) < editShowAreaAbsRect.y) && ((endRect.y + endRect.height) > (editShowAreaAbsRect.y + editShowAreaAbsRect.height)))
2013                 {
2014                         copyPastePoint.y = editShowAreaAbsRect.y + editShowAreaAbsRect.height/2;
2015
2016                         if (copyPastePoint.y < __contextMenuHeight)
2017                         {
2018                                 __contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_DOWN;
2019                         }
2020
2021                 }
2022                 // Left handler is located on the top of the Editor and Right handler is located on the Editor
2023                 else if ( ((startRect.y + startRect.height) < editShowAreaAbsRect.y) && ((endRect.y + endRect.height) <= (editShowAreaAbsRect.y + editShowAreaAbsRect.height)) )
2024                 {
2025                         if ( (endRect.y + endRect.height + handlerHeight + __contextMenuHeight) < keypadBounds.y)
2026                         {
2027                                 __contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_DOWN;
2028                                 copyPastePoint.y = endRect.y + endRect.height + handlerHeight;
2029                         }
2030                         else if (endRect.y - editShowAreaAbsRect.y > __contextMenuHeight)
2031                         {
2032                                 copyPastePoint.y = editShowAreaAbsRect.y + __contextMenuHeight;
2033                         }
2034                         else if (endRect.y > __contextMenuHeight)
2035                         {
2036                                 copyPastePoint.y = endRect.y;
2037                         }
2038                         else
2039                         {
2040                                 SysLog(NID_UI_CTRL, "There is no space to draw the copy&paste popup\n");
2041                                 return;
2042                         }
2043                 }
2044                 // Left handler is located on the Editor and Right handler is located on the bottom of the Editor
2045                 else if ( ((startRect.y + startRect.height) >= editShowAreaAbsRect.y) && ((endRect.y + endRect.height) > (editShowAreaAbsRect.y + editShowAreaAbsRect.height)) )
2046                 {
2047                         if (__contextMenuHeight < startRect.y)
2048                         {
2049                                 copyPastePoint.y = startRect.y;
2050                         }
2051                         else
2052                         {
2053                                 copyPastePoint.y = startRect.y + (editShowAreaAbsRect.y + editShowAreaAbsRect.height - startRect.y)/2;
2054                         }
2055                 }
2056                 // There is a  space on the top of the Editor.
2057                 else if (__contextMenuHeight < startRect.y)
2058                 {
2059                         copyPastePoint.y = startRect.y;
2060                 }
2061                 // There is a  space on the bottom of the Editor.
2062                 else if ( screenSize.height  > (endRect.y + endRect.height + handlerHeight + __contextMenuHeight))
2063                 {
2064                         __contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_DOWN;
2065
2066                         copyPastePoint.y = endRect.y + endRect.height + handlerHeight;
2067                 }
2068                 // There is no space on the top and bottom of the Editor. The Popup should be drawn on the center of the Editor.
2069                 else
2070                 {
2071                         if (endRect.y - startRect.y < __contextMenuHeight)
2072                         {
2073                                 SysLog(NID_UI_CTRL, "There is no space to draw the copy&paste popup\n");
2074                                 return;
2075                         }
2076                         copyPastePoint.y = startRect.y + __contextMenuHeight;
2077                 }
2078         }
2079
2080         else
2081         {
2082                 if (editShowAreaAbsRect.height <= 0)
2083                 {
2084                         return;
2085                 }
2086                 FloatRectangle cursorRect;
2087                 bool reverseHandler = false;
2088                 int cursorPosition = GetCursorPosition();
2089                 __pEdit->CalculateAbsoluteCursorBounds(cursorPosition, cursorRect);
2090                 copyPastePoint.x = cursorRect.x;
2091                 copyPastePoint.y = cursorRect.y;
2092
2093                 if (!_FloatCompare(__editVisibleArea.y + __editVisibleArea.height, copyPastePoint.y) && __editVisibleArea.y + __editVisibleArea.height < copyPastePoint.y)
2094                 {
2095                         return;
2096                 }
2097
2098                 if (!_FloatCompare(__editVisibleArea.y, copyPastePoint.y) && __editVisibleArea.y > copyPastePoint.y)
2099                 {
2100                         if (!_FloatCompare(__editVisibleArea.y + __editVisibleArea.height, copyPastePoint.y + cursorRect.height) && (__editVisibleArea.y + __editVisibleArea.height > copyPastePoint.y + cursorRect.height))
2101                         {
2102                                 reverseHandler = true;
2103                         }
2104                         else
2105                         {
2106                                 return;
2107                         }
2108                 }
2109
2110                 if (copyPastePoint.y < __contextMenuHeight || reverseHandler)
2111                 {
2112                         FloatRectangle cursorRect = GetCursorBoundsF(true);
2113
2114                         copyPastePoint.y += cursorRect.height;
2115                         __contextMenuAlign = CONTEXT_MENU_CORE_ALIGN_DOWN;
2116                         if (__pHandle[HANDLER_TYPE_CENTER])
2117                         {
2118                                 copyPastePoint.y += __pHandle[HANDLER_TYPE_CENTER]->GetBounds().height;
2119                         }
2120                 }
2121         }
2122
2123         //Todo: Create API  ex)CreateContrexMenuFN
2124         __pCopyPastePopup = _ContextMenu::CreateContextMenuN(copyPastePoint, CONTEXT_MENU_CORE_STYLE_GRID, __contextMenuAlign);
2125         SysTryReturnVoidResult(NID_UI_CTRL, __pCopyPastePopup, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2126
2127         if ( __pEdit->GetTextLength() != 0  && !isPasswordStyle)
2128         {
2129                 if (__pEdit->IsBlocked())
2130                 {
2131                         String copyText;
2132                         String cutText;
2133
2134                         GET_STRING_CONFIG(IDS_TPLATFORM_OPT_COPY, copyText);
2135                         GET_STRING_CONFIG(IDS_TPLATFORM_OPT_CUT, cutText);
2136
2137                         __pCopyPastePopup->AddItem(copyText, COPY_PASTE_COPY_ID, null, null, null);
2138                         if (!__pEditPresenter->IsViewModeEnabled())
2139                         {
2140                                 __pCopyPastePopup->AddItem(cutText, COPY_PASTE_CUT_ID, null, null, null);
2141                         }
2142                 }
2143                 else
2144                 {
2145                         String selectText;
2146                         String selectAllText;
2147
2148                         GET_STRING_CONFIG(IDS_TPLATFORM_OPT_SELECT, selectText);
2149                         GET_STRING_CONFIG(IDS_TPLATFORM_OPT_SELECT_ALL, selectAllText);
2150
2151                         __pCopyPastePopup->AddItem(selectText, COPY_PASTE_SELECT_ID, null, null, null);
2152                         __pCopyPastePopup->AddItem(selectAllText, COPY_PASTE_SELECT_ALL_ID, null, null, null);
2153                 }
2154         }
2155
2156         if (isClipped)
2157         {
2158                 if (!__pEditPresenter->IsViewModeEnabled())
2159                 {
2160                         String pasteText;
2161                         String clipboardText;
2162
2163                         GET_STRING_CONFIG(IDS_TPLATFORM_OPT_PASTE, pasteText);
2164                         GET_STRING_CONFIG(IDS_TPLATFORM_OPT_CLIPBOARD, clipboardText);
2165
2166                         __pCopyPastePopup->AddItem(pasteText, COPY_PASTE_PASTE_ID, null, null, null);
2167                         if (!isPasswordStyle && __pEdit->IsKeypadEnabled())
2168                         {
2169                                 __pCopyPastePopup->AddItem(clipboardText, COPY_PASTE_CLIPBOARD_ID, null, null, null);
2170                         }
2171                 }
2172         }
2173
2174         __pCopyPastePopup->AddActionEventListener(*this);
2175         return;
2176 /*
2177         Bitmap* pSearchNormalBitmap = null;
2178         Bitmap* pSearchPressedBitmap = null;
2179
2180         Color searchColor;
2181         Color searchPressedColor;
2182         result r = E_SUCCESS;
2183
2184         if (__pEdit->IsBlocked() && !isPasswordStyle)
2185         {
2186                 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_NORMAL, searchColor);
2187                 GET_COLOR_CONFIG(CONTEXTMENU::ITEM_TEXT_PRESSED, searchPressedColor);
2188
2189                 r = GET_REPLACED_BITMAP_CONFIG_N(EDIT::COPY_PASTE_SEARCH_ICON, BITMAP_PIXEL_FORMAT_ARGB8888, searchColor, pSearchNormalBitmap);
2190                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), r, r,"[%s] Propagating.", GetErrorMessage(r));
2191
2192                 r = GET_REPLACED_BITMAP_CONFIG_N(EDIT::COPY_PASTE_SEARCH_ICON, BITMAP_PIXEL_FORMAT_ARGB8888, searchPressedColor, pSearchPressedBitmap);
2193                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), r, r,"[%s] Propagating.", GetErrorMessage(r));
2194
2195                 __pCopyPastePopup->AddItem(null, COPY_PASTE_SEARCH_ID, pSearchNormalBitmap, pSearchPressedBitmap, null);
2196         }
2197
2198         if (pSearchNormalBitmap)
2199         {
2200                 delete pSearchNormalBitmap;
2201                 pSearchNormalBitmap = null;
2202         }
2203         if (pSearchPressedBitmap)
2204         {
2205                 delete pSearchPressedBitmap;
2206                 pSearchPressedBitmap = null;
2207         }
2208         __pCopyPastePopup->AddActionEventListener(*this);
2209
2210         return;
2211
2212 CATCH:
2213         delete pSearchNormalBitmap;
2214         pSearchNormalBitmap = null;
2215
2216         delete pSearchPressedBitmap;
2217         pSearchPressedBitmap = null;
2218
2219         return;
2220 */
2221 }
2222
2223 void
2224 _EditCopyPasteManager::CreateHandle(void)
2225 {
2226         ReleaseHandle();
2227
2228         if (__pEdit->IsBlocked())
2229         {
2230                 int start = -1;
2231                 int end = -1;
2232                 FloatRectangle startRect;
2233                 FloatRectangle endRect;
2234
2235                 __pEdit->GetBlockRange(start, end);
2236
2237                 __pEdit->CalculateAbsoluteCursorBounds(start, startRect);
2238                 __pEdit->CalculateAbsoluteCursorBounds(end, endRect);
2239
2240                 FloatPoint leftHandler(startRect.x, startRect.y + startRect.height);
2241                 FloatPoint rightHandler(endRect.x, endRect.y + endRect.height);
2242
2243                 __pHandle[HANDLER_TYPE_LEFT] = _EditCopyPasteHandler::CreateInstanceN(leftHandler, start, this, false, true);
2244                 __pHandle[HANDLER_TYPE_RIGHT] = _EditCopyPasteHandler::CreateInstanceN(rightHandler, end, this, false, false);
2245         }
2246         else
2247         {
2248                 FloatRectangle centerRect;
2249                 __pEdit->CalculateAbsoluteCursorBounds(__pEdit->GetCursorPosition(), centerRect);
2250                 FloatPoint centerHandler(centerRect.x, centerRect.y + centerRect.height);
2251
2252                 __pHandle[HANDLER_TYPE_CENTER] = _EditCopyPasteHandler::CreateInstanceN(centerHandler, __pEdit->GetCursorPosition(), this, true, true);
2253 #if EDIT_COPY_PASTE_MAGNIFIER
2254                 __pHandle[HANDLER_TYPE_CENTER]->CreateCopyPasteMagnifier();
2255 #endif
2256         }
2257 }
2258
2259 void
2260 _EditCopyPasteManager::CreateHandle(int start, int end, int startRowIndex, int startColumnIndex, int endRowIndex, int endColumnIndex)
2261 {
2262         ReleaseHandle();
2263
2264         if (__pEdit->IsBlocked())
2265         {
2266                 FloatRectangle startRect;
2267                 FloatRectangle endRect;
2268
2269                 if (startRowIndex > -1 && startColumnIndex > -1)
2270                 {
2271                         __pEditPresenter->CalculateAbsoluteCursorBounds(startRowIndex, startColumnIndex, startRect);
2272                 }
2273                 else
2274                 {
2275                         __pEditPresenter->CalculateAbsoluteCursorBounds(start, startRect);
2276                 }
2277                 if (endRowIndex > -1 && endColumnIndex > -1)
2278                 {
2279                         __pEditPresenter->CalculateAbsoluteCursorBounds(endRowIndex, endColumnIndex, endRect);
2280                 }
2281                 else
2282                 {
2283                         __pEditPresenter->CalculateAbsoluteCursorBounds(end, endRect);
2284                 }
2285
2286                 FloatPoint leftHandler(startRect.x, startRect.y + startRect.height);
2287                 FloatPoint rightHandler(endRect.x, endRect.y + endRect.height);
2288
2289                 __pHandle[HANDLER_TYPE_LEFT] = _EditCopyPasteHandler::CreateInstanceN(leftHandler, start, this, false, true);
2290                 __pHandle[HANDLER_TYPE_RIGHT] = _EditCopyPasteHandler::CreateInstanceN(rightHandler, end, this, false, false);
2291
2292                 if (startRowIndex > -1 && startColumnIndex > -1)
2293                 {
2294                         __pHandle[HANDLER_TYPE_LEFT]->SetHandlerRowColumnIndex(startRowIndex, startColumnIndex);
2295                 }
2296                 if (endRowIndex > -1 && endColumnIndex > -1)
2297                 {
2298                         __pHandle[HANDLER_TYPE_RIGHT]->SetHandlerRowColumnIndex(endRowIndex, endColumnIndex);
2299                 }
2300                 AdjustBounds();
2301         }
2302 }
2303
2304 void
2305 _EditCopyPasteManager::Show(void)
2306 {
2307         if (__pHandle[HANDLER_TYPE_CENTER])
2308         {
2309                 if (__pEdit->GetCursorPosition() != __pHandle[HANDLER_TYPE_CENTER]->GetHandlerCursorPosition())
2310                 {
2311                         __pHandle[HANDLER_TYPE_CENTER]->SetHandlerCursorPosition(__pEdit->GetCursorPosition());
2312                 }
2313                 __pHandle[HANDLER_TYPE_CENTER]->AdjustBounds();
2314                 __pHandle[HANDLER_TYPE_CENTER]->CheckReverseStatus();
2315                 __pHandle[HANDLER_TYPE_CENTER]->Invalidate();
2316                 __pEditPresenter->DrawText();
2317                 __pHandle[HANDLER_TYPE_CENTER]->MoveCopyPasteMagnifier();
2318         }
2319
2320         if (__pHandle[HANDLER_TYPE_LEFT] && __pHandle[HANDLER_TYPE_RIGHT])
2321         {
2322                 AdjustBounds();
2323                 __pHandle[HANDLER_TYPE_LEFT]->CheckReverseStatus();
2324                 __pHandle[HANDLER_TYPE_RIGHT]->CheckReverseStatus();
2325                 __pHandle[HANDLER_TYPE_LEFT]->Invalidate();
2326                 __pHandle[HANDLER_TYPE_RIGHT]->Invalidate();
2327                 __pEditPresenter->DrawText();
2328         }
2329
2330         if (__pCopyPastePopup)
2331         {
2332                 __pCopyPastePopup->Open();
2333                 __pCopyPastePopup->ReleaseTouchCapture();
2334
2335                 _Control* pControl = __pCopyPastePopup->GetOwner();
2336                 if (pControl)
2337                 {
2338                         pControl->UnlockInputEvent();
2339                 }
2340         }
2341 }
2342
2343 bool
2344 _EditCopyPasteManager::CheckHandleBounds(const FloatPoint& point)
2345 {
2346         bool hasCommandButton = false;
2347         bool hasParentForm = false;
2348         bool hasParentPanel = false;
2349         bool showCheck = true;
2350         FloatRectangle commandButtonBounds(0.0f, 0.0f, 0.0f, 0.0f);
2351         FloatRectangle formClientBounds(0.0f, 0.0f, 0.0f, 0.0f);
2352         FloatRectangle panelAbsoulteBounds(0.0f, 0.0f, 0.0f, 0.0f);
2353         FloatRectangle editAbsBounds = __pEdit->GetAbsoluteBoundsF(true);
2354         FloatRectangle textObjectBounds = __pEditPresenter->GetTextBoundsF();
2355
2356         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN))
2357         {
2358                 editAbsBounds.x += textObjectBounds.x;
2359                 editAbsBounds.y += textObjectBounds.y;
2360                 editAbsBounds.width = textObjectBounds.width;
2361
2362                 if (!(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE))
2363                 {
2364                         editAbsBounds.height = textObjectBounds.height;
2365                 }
2366         }
2367
2368         _Toolbar* pCommandButton = __pEditPresenter->GetKeypadCommandButton();
2369         if (pCommandButton)
2370         {
2371                 commandButtonBounds = pCommandButton->GetAbsoluteBoundsF(true);
2372                 hasCommandButton = true;
2373         }
2374         _Form* pForm = __pEditPresenter->GetParentForm();
2375         if (pForm)
2376         {
2377                 formClientBounds = pForm->GetClientBoundsF();
2378                 hasParentForm = true;
2379         }
2380
2381         _ScrollPanel* pPanel = __pEditPresenter->GetParentPanel();
2382         if (pPanel)
2383         {
2384                 panelAbsoulteBounds = pPanel->GetAbsoluteBoundsF(true);
2385                 hasParentPanel = true;
2386         }
2387
2388         if ((!_FloatCompare(editAbsBounds.x, point.x) && (editAbsBounds.x > point.x)) || (!_FloatCompare(point.x, editAbsBounds.x + editAbsBounds.width) && point.x > (editAbsBounds.x + editAbsBounds.width)))
2389         {
2390                 showCheck = false;
2391         }
2392
2393         if ((!_FloatCompare(editAbsBounds.y, point.y) && (editAbsBounds.y > point.y)) || (!_FloatCompare(point.y, editAbsBounds.y + editAbsBounds.height) && point.y > (editAbsBounds.y + editAbsBounds.height)))
2394         {
2395                 showCheck = false;
2396         }
2397         if (hasParentForm && ((!_FloatCompare(formClientBounds.y, point.y) && formClientBounds.y > point.y) || (!_FloatCompare(point.y, formClientBounds.y + formClientBounds.height) && point.y > (formClientBounds.y + formClientBounds.height))))
2398         {
2399                 showCheck = false;
2400         }
2401         if (hasParentPanel && ((!_FloatCompare(panelAbsoulteBounds.y, point.y) && panelAbsoulteBounds.y > point.y) || (!_FloatCompare(point.y, panelAbsoulteBounds.y + panelAbsoulteBounds.height) && point.y > (panelAbsoulteBounds.y + panelAbsoulteBounds.height))))
2402         {
2403                 showCheck = false;
2404         }
2405         if (hasCommandButton && commandButtonBounds.Contains(point))
2406         {
2407                 showCheck = false;
2408         }
2409         return showCheck;
2410 }
2411
2412 void
2413 _EditCopyPasteManager::RefreshBlock(bool isLeftHandle)
2414 {
2415         int leftRowIndex = -1;
2416         int leftColumnIndex = -1;
2417         int rightRowIndex = -1;
2418         int rightColumnIndex = -1;
2419
2420         int leftHandlerPos = __pHandle[HANDLER_TYPE_LEFT]->GetHandlerCursorPosition();
2421         int rightHandlerPos = __pHandle[HANDLER_TYPE_RIGHT]->GetHandlerCursorPosition();
2422         __pHandle[HANDLER_TYPE_LEFT]->GetHandlerRowColumnIndex(leftRowIndex, leftColumnIndex);
2423         __pHandle[HANDLER_TYPE_RIGHT]->GetHandlerRowColumnIndex(rightRowIndex, rightColumnIndex);
2424
2425         if (leftHandlerPos <= rightHandlerPos)
2426         {
2427                 if (leftRowIndex != -1 && leftColumnIndex != -1 && rightRowIndex != -1 && rightColumnIndex != -1)
2428                 {
2429                         __pEditPresenter->SetBlockRange(leftHandlerPos, rightHandlerPos, leftRowIndex, leftColumnIndex, rightRowIndex, rightColumnIndex);
2430                 }
2431                 else
2432                 {
2433                         __pEditPresenter->SetBlockRange(leftHandlerPos, rightHandlerPos);
2434                 }
2435                 __pEditPresenter->SetCursorChangedFlag(!isLeftHandle);
2436         }
2437         else
2438         {
2439                 if (leftRowIndex != -1 && leftColumnIndex != -1 && rightRowIndex != -1 && rightColumnIndex != -1)
2440                 {
2441                         __pEditPresenter->SetBlockRange(rightHandlerPos, leftHandlerPos, rightRowIndex, rightColumnIndex, leftRowIndex, leftColumnIndex);
2442                 }
2443                 else
2444                 {
2445                         __pEditPresenter->SetBlockRange(rightHandlerPos, leftHandlerPos);
2446                 }
2447                 __pEditPresenter->SetCursorChangedFlag(isLeftHandle);
2448         }
2449         __pEditPresenter->DrawText();
2450         AdjustBounds();
2451 }
2452
2453 FloatRectangle
2454 _EditCopyPasteManager::GetCursorBoundsF(bool isAbsRect) const
2455 {
2456         FloatRectangle cursorBounds;
2457
2458         __pEdit->GetCursorBounds(isAbsRect, cursorBounds);
2459
2460         return cursorBounds;
2461 }
2462
2463 int
2464 _EditCopyPasteManager::GetCursorPositionAt(const FloatPoint& touchPoint) const
2465 {
2466         return __pEdit->GetCursorPositionAt(touchPoint);
2467 }
2468
2469 result
2470 _EditCopyPasteManager::SetCursorPosition(int position)
2471 {
2472         return __pEdit->SetCursorPosition(position);
2473 }
2474
2475 int
2476 _EditCopyPasteManager::GetCursorPosition(void) const
2477 {
2478         return __pEdit->GetCursorPosition();
2479 }
2480
2481 int
2482 _EditCopyPasteManager::GetHandlerCursorPosition(HandlerType handlerType) const
2483 {
2484         if (__pHandle[handlerType])
2485         {
2486                 return __pHandle[handlerType]->GetHandlerCursorPosition();
2487         }
2488         else
2489         {
2490                 return -1;
2491         }
2492 }
2493
2494 void
2495 _EditCopyPasteManager::SendTextBlockEvent(void)
2496 {
2497         int start = -1;
2498         int end = -1;
2499         result r = E_SUCCESS;
2500
2501         __pEdit->GetBlockRange(start, end);
2502         if (start != -1 && end != -1)
2503         {
2504                 r = __pEdit->SendTextBlockEvent(start, end);
2505                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2506         }
2507 }
2508
2509 void
2510 _EditCopyPasteManager::OnActionPerformed(const _Control& source, int actionId)
2511 {
2512         _Clipboard* pClipBoard = _Clipboard::GetInstance();
2513         SysTryReturnVoidResult(NID_UI_CTRL, pClipBoard, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2514
2515         ReleaseCopyPastePopup();
2516
2517         switch (actionId)
2518         {
2519         case COPY_PASTE_SELECT_ID:
2520                 {
2521                         int cursorPos = GetCursorPosition();
2522                         int start, end;
2523
2524                         __pEdit->GetWordPosition(cursorPos, start, end);
2525                         __pEdit->SetBlockRange(start, end);
2526                         SendTextBlockEvent();
2527                         __pEditPresenter->UpdateComponentInformation();
2528                         CreateHandle();
2529                         CreateCopyPastePopup();
2530                         Show();
2531
2532                         __pEdit->Draw();
2533                 }
2534                 break;
2535
2536         case COPY_PASTE_SELECT_ALL_ID:
2537                 {
2538                         int textLength = __pEdit->GetTextLength();
2539                         __pEdit->SetBlockRange(0, textLength);
2540                         SendTextBlockEvent();
2541                         __pEditPresenter->UpdateComponentInformation();
2542                         CreateHandle();
2543                         CreateCopyPastePopup();
2544                         Show();
2545
2546                         __pEdit->Draw();
2547                 }
2548                 break;
2549
2550         case COPY_PASTE_COPY_ID:
2551                 ReleaseCopyPastePopup();
2552                 SendCopyPasteEvent(CORE_COPY_PASTE_STATUS_HIDE, CORE_COPY_PASTE_ACTION_COPY);
2553                 break;
2554
2555         case COPY_PASTE_CUT_ID:
2556                 SendCopyPasteEvent(CORE_COPY_PASTE_STATUS_HIDE, CORE_COPY_PASTE_ACTION_CUT);
2557                 break;
2558
2559         case COPY_PASTE_PASTE_ID:
2560                 SendCopyPasteEvent(CORE_COPY_PASTE_STATUS_HIDE, CORE_COPY_PASTE_ACTION_PASTE);
2561                 break;
2562
2563         case COPY_PASTE_CLIPBOARD_ID:
2564                 pClipBoard->ShowPopup(CLIPBOARD_DATA_TYPE_TEXT, *__pEdit, true);
2565                 ReleaseCopyPastePopup();
2566                 SendCopyPasteEvent(CORE_COPY_PASTE_STATUS_HIDE, CORE_COPY_PASTE_ACTION_CLIPBOARD);
2567                 break;
2568         case COPY_PASTE_SEARCH_ID:
2569                 LaunchSearch();
2570                 SendCopyPasteEvent(CORE_COPY_PASTE_STATUS_HIDE, CORE_COPY_PASTE_ACTION_SEARCH);
2571                 break;
2572         default:
2573                 break;
2574         }
2575
2576         return;
2577 }
2578
2579 void
2580 _EditCopyPasteManager::AdjustBounds(void)
2581 {
2582         if (__pHandle[HANDLER_TYPE_CENTER])
2583         {
2584                 __pHandle[HANDLER_TYPE_CENTER]->AdjustBounds();
2585         }
2586         if (__pHandle[HANDLER_TYPE_LEFT])
2587         {
2588                 __pHandle[HANDLER_TYPE_LEFT]->AdjustBounds();
2589         }
2590         if (__pHandle[HANDLER_TYPE_RIGHT])
2591         {
2592                 __pHandle[HANDLER_TYPE_RIGHT]->AdjustBounds();
2593         }
2594 }
2595
2596 void
2597 _EditCopyPasteManager::LaunchSearch(void)
2598 {
2599         result r = E_SUCCESS;
2600         int start = -1;
2601         int end = -1;
2602         __pEdit->GetBlockRange(start, end);
2603         String blockText = __pEditPresenter->GetText(start, end-1);
2604
2605         _AppMessageImpl msg;
2606
2607         msg.AddData(APPSVC_DATA_KEYWORD, blockText);
2608         r = _AppControlManager::GetInstance()->LaunchPkg(msg, null, APPSVC_OPERATION_SEARCH, null, null, 0, 0);
2609 }
2610
2611 bool
2612 _EditCopyPasteManager::GetTextBlockReleaseFlag(void) const
2613 {
2614         return __needToReleaseBlock;
2615 }
2616
2617 void
2618 _EditCopyPasteManager::SetTextBlockReleaseFlag(bool enabled)
2619 {
2620         __needToReleaseBlock = enabled;
2621 }
2622
2623 bool
2624 _EditCopyPasteManager::IsCopyPasteHandleExist(void) const
2625 {
2626         if (__pHandle[HANDLER_TYPE_CENTER] || (__pHandle[HANDLER_TYPE_LEFT] && __pHandle[HANDLER_TYPE_RIGHT]))
2627         {
2628                 return true;
2629         }
2630         else
2631         {
2632                 return false;
2633         }
2634 }
2635
2636 bool
2637 _EditCopyPasteManager::IsCopyPasteSingleHandleExist(void) const
2638 {
2639         if (__pHandle[HANDLER_TYPE_CENTER])
2640         {
2641                 return true;
2642         }
2643         else
2644         {
2645                 return false;
2646         }
2647 }
2648
2649 void
2650 _EditCopyPasteManager::UpdateCopyPasteMagnifier(void)
2651 {
2652         for (int i = 0; i < HANDLER_TYPE_MAX; i++)
2653         {
2654                 if (__pHandle[i])
2655                 {
2656                         __pHandle[i]->UpdateCopyPasteMagnifier();
2657                 }
2658         }
2659 }
2660
2661 _Edit*
2662 _EditCopyPasteManager::GetEdit(void) const
2663 {
2664         return __pEdit;
2665 }
2666
2667 void
2668 _EditCopyPasteManager::MoveHandler(HandlerMoveType moveType)
2669 {
2670         if (!__pHandle[HANDLER_TYPE_RIGHT] || !__pHandle[HANDLER_TYPE_LEFT])
2671         {
2672                 return;
2673         }
2674
2675         int leftHandlerPosition = __pHandle[HANDLER_TYPE_LEFT]->GetHandlerCursorPosition();
2676         int rightHandlerPosition = __pHandle[HANDLER_TYPE_RIGHT]->GetHandlerCursorPosition();
2677         int textLength = __pEdit->GetTextLength();
2678        FloatRectangle rightHandlerCursorBounds;
2679         int newCursorPosition;
2680         __pEditPresenter->CalculateCursorBounds(__pEditPresenter->GetTextBoundsF(), rightHandlerCursorBounds, rightHandlerPosition);
2681         FloatPoint cursorPoint(rightHandlerCursorBounds.x, rightHandlerCursorBounds.y);
2682
2683         TextObject* pTextObject = __pEditPresenter->GetTextObject();
2684
2685         switch(moveType)
2686         {
2687                 case HANDLER_MOVE_TYPE_LEFT:
2688                         if (leftHandlerPosition == rightHandlerPosition-1)
2689                         {
2690                                 if (leftHandlerPosition == 0)
2691                                 {
2692                                         return;
2693                                 }
2694                                 --rightHandlerPosition;
2695                         }
2696                         if (rightHandlerPosition - 1 < 0)
2697                         {
2698                                 return;
2699                         }
2700                         newCursorPosition = --rightHandlerPosition;
2701                         __pHandle[HANDLER_TYPE_RIGHT]->SetHandlerCursorPosition(newCursorPosition);
2702                         pTextObject->SetFirstDisplayLineIndexFromTextIndex(newCursorPosition);
2703                         __pEditPresenter->ScrollPanelToCursorPosition(true);
2704                         RefreshBlock();
2705                         __pHandle[HANDLER_TYPE_RIGHT]->CheckReverseStatus();
2706                         __pHandle[HANDLER_TYPE_RIGHT]->Invalidate();
2707                         break;
2708                 case HANDLER_MOVE_TYPE_UP:
2709                         cursorPoint.y -= rightHandlerCursorBounds.height/2.0f;
2710                         newCursorPosition = GetCursorPositionAt(cursorPoint);
2711
2712                         if (newCursorPosition <= 0)
2713                         {
2714                                 int curCursorLine = pTextObject->GetLineIndexAtTextIndex(pTextObject->GetCursorIndex());
2715
2716                                 if (curCursorLine !=0 )
2717                                 {
2718                                         int offset = rightHandlerPosition - pTextObject->GetFirstTextIndexAt(curCursorLine);
2719                                         int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine-1);
2720                                         newCursorPosition = offset + firstTextIndex;
2721                                         int textLength = pTextObject->GetTextLengthAt(curCursorLine-1);
2722                                         if (offset > textLength)
2723                                         {
2724                                                 newCursorPosition = firstTextIndex+textLength;
2725                                         }
2726                                 }
2727                         }
2728
2729                         if (newCursorPosition >= 0)
2730                         {
2731                                 if (leftHandlerPosition == newCursorPosition)
2732                                 {
2733                                         ++newCursorPosition;
2734                                 }
2735                                 __pHandle[HANDLER_TYPE_RIGHT]->SetHandlerCursorPosition(newCursorPosition);
2736                                 pTextObject->SetFirstDisplayLineIndexFromTextIndex(newCursorPosition);
2737                                 __pEditPresenter->ScrollPanelToCursorPosition(true);
2738                                 RefreshBlock();
2739                                 __pHandle[HANDLER_TYPE_RIGHT]->CheckReverseStatus();
2740                                 __pHandle[HANDLER_TYPE_RIGHT]->Invalidate();
2741                         }
2742                         else
2743                         {
2744                                 return;
2745                         }
2746                         break;
2747                 case HANDLER_MOVE_TYPE_DOWN:
2748                         cursorPoint.y += rightHandlerCursorBounds.height + rightHandlerCursorBounds.height/2.0f;
2749                         newCursorPosition = GetCursorPositionAt(cursorPoint);
2750
2751                         if (newCursorPosition < 0)
2752                         {
2753                                 int curCursorLine = pTextObject->GetLineIndexAtTextIndex(pTextObject->GetCursorIndex());
2754                                 int totalLine = pTextObject->GetTotalLineCount();
2755                                 if (curCursorLine < totalLine - 1)
2756                                 {
2757                                         int offset = rightHandlerPosition - pTextObject->GetFirstTextIndexAt(curCursorLine);
2758                                         int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine+1);
2759                                         newCursorPosition = offset + firstTextIndex;
2760                                         int textLength = pTextObject->GetTextLengthAt(curCursorLine+1);
2761                                         if (offset > textLength)
2762                                         {
2763                                                 newCursorPosition = firstTextIndex+textLength;
2764
2765                                         }
2766                                 }
2767                                 else if (curCursorLine == totalLine - 1)
2768                                 {
2769                                         int firstTextIndex = pTextObject->GetFirstTextIndexAt(curCursorLine);
2770                                         int textLength = pTextObject->GetTextLengthAt(curCursorLine);
2771                                         newCursorPosition = firstTextIndex + textLength;
2772                                 }
2773                         }
2774
2775                         if (newCursorPosition >= 0)
2776                         {
2777                                 if (leftHandlerPosition == newCursorPosition)
2778                                 {
2779                                         ++newCursorPosition;
2780                                 }
2781                                 __pHandle[HANDLER_TYPE_RIGHT]->SetHandlerCursorPosition(newCursorPosition);
2782                                 pTextObject->SetFirstDisplayLineIndexFromTextIndex(newCursorPosition);
2783                                 __pEditPresenter->ScrollPanelToCursorPosition(true);
2784                                 RefreshBlock();
2785                                 __pHandle[HANDLER_TYPE_RIGHT]->CheckReverseStatus();
2786                                 __pHandle[HANDLER_TYPE_RIGHT]->Invalidate();
2787                         }
2788                         else
2789                         {
2790                                 return;
2791                         }
2792                         break;
2793                 case HANDLER_MOVE_TYPE_RIGHT:
2794                         if (textLength >= rightHandlerPosition+1)
2795                         {
2796                                 if (leftHandlerPosition == rightHandlerPosition+1)
2797                                 {
2798                                         ++rightHandlerPosition;
2799                                 }
2800                                 newCursorPosition = ++rightHandlerPosition;
2801                                 __pHandle[HANDLER_TYPE_RIGHT]->SetHandlerCursorPosition(newCursorPosition);
2802                                 pTextObject->SetFirstDisplayLineIndexFromTextIndex(newCursorPosition);
2803                                 __pEditPresenter->ScrollPanelToCursorPosition(true);
2804                                 RefreshBlock();
2805                                 __pHandle[HANDLER_TYPE_RIGHT]->CheckReverseStatus();
2806                                 __pHandle[HANDLER_TYPE_RIGHT]->Invalidate();
2807                         }
2808                         else
2809                         {
2810                                 return;
2811                         }
2812                         break;
2813                 default:
2814                         break;
2815         }
2816
2817         ReleaseCopyPastePopup();
2818         __isHandlerMoving = true;
2819         return;
2820 }
2821
2822 bool
2823 _EditCopyPasteManager::IsHandlerMovingEnabled(void) const
2824 {
2825         return __isHandlerMoving;
2826 }
2827
2828 void
2829 _EditCopyPasteManager::SetHandlerMovingEnabled(bool enabled)
2830 {
2831         __isHandlerMoving = enabled;
2832 }
2833
2834 Rectangle
2835 _EditCopyPasteManager::GetEditVisibleArea(void) const
2836 {
2837         return _CoordinateSystemUtils::ConvertToInteger(GetEditVisibleAreaF());
2838 }
2839
2840 FloatRectangle
2841 _EditCopyPasteManager::GetEditVisibleAreaF(void) const
2842 {
2843         return __editVisibleArea;
2844 }
2845
2846 _ContextMenu*
2847 _EditCopyPasteManager::GetCopyPastePopup(void) const
2848 {
2849         return __pCopyPastePopup;
2850 }
2851
2852 void
2853 _EditCopyPasteManager::GetHandlerRowColumnIndex(bool singleHandler, bool leftHandler, int& rowIndex, int& columnIndex) const
2854 {
2855         HandlerType handlerType = HANDLER_TYPE_MAX;
2856         if (singleHandler)
2857         {
2858                 handlerType = HANDLER_TYPE_CENTER;
2859         }
2860         else if (leftHandler)
2861         {
2862                 handlerType = HANDLER_TYPE_LEFT;
2863         }
2864         else
2865         {
2866                 handlerType = HANDLER_TYPE_RIGHT;
2867         }
2868
2869         if (__pHandle[handlerType])
2870         {
2871                 __pHandle[handlerType]->GetHandlerRowColumnIndex(rowIndex, columnIndex);
2872         }
2873         else
2874         {
2875                 rowIndex = -1;
2876                 columnIndex = -1;
2877         }
2878
2879         return;
2880 }
2881
2882 void
2883 _EditCopyPasteManager::DestroyCopyPasteMagnifier(void)
2884 {
2885         //only single case.
2886         if (__pHandle[HANDLER_TYPE_CENTER])
2887         {
2888                 __pHandle[HANDLER_TYPE_CENTER]->DestroyCopyPasteMagnifier();
2889         }
2890 }
2891
2892 void
2893 _EditCopyPasteManager::CreateCopyPasteMagnifier(void)
2894 {
2895         //only single case.
2896         if (__pHandle[HANDLER_TYPE_CENTER])
2897         {
2898                 __pHandle[HANDLER_TYPE_CENTER]->CreateCopyPasteMagnifier();
2899         }
2900 }
2901
2902 }}} // Tizen::Ui::Controls