modify Klockwork bug
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_EditPresenter.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_EditPresenter.cpp
20  * @brief               This is the implementation file for the _EditPresenter class.
21  */
22
23 #include <FBaseErrorDefine.h>
24 #include <FBaseInternalTypes.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilMath.h>
27 #include <FGrpFloatRectangle.h>
28 #include <FGrpFont.h>
29 #include <FLclLocale.h>
30 #include <FUiCtrlFooter.h>
31 #include <FUiCtrlFooterItem.h>
32 #include <FUiCtrlForm.h>
33 #include <FUiIActionEventListener.h>
34 #include <FGrp_BitmapImpl.h>
35 #include <FGrp_CoordinateSystem.h>
36 #include <FGrp_FontImpl.h>
37 #include <FGrp_Screen.h>
38 #include <FGrp_TextCommon.h>
39 #include <FGrp_TextElementImpl.h>
40 #include <FGrp_TextTextCutLink.h>
41 #include <FGrp_TextTextCutLinkParser.h>
42 #include <FGrp_TextTextElement.h>
43 #include <FGrp_TextTextImage.h>
44 #include <FGrp_TextTextSimple.h>
45 #include "FUi_Clipboard.h"
46 #include "FUi_ClipboardItem.h"
47 #include "FUi_Control.h"
48 #include "FUi_ControlManager.h"
49 #include "FUi_CoordinateSystemUtils.h"
50 #include "FUi_EcoreEvasMgr.h"
51 #include "FUi_ResourceManager.h"
52 #include "FUi_BidiUtils.h"
53 #include "FUi_UiEventManager.h"
54 #include "FUi_UiNotificationEvent.h"
55 #include "FUiAnim_VisualElement.h"
56 #include "FUiAnim_EflNode.h"
57 #include "FUiCtrl_Button.h"
58 #include "FUiCtrl_ContextMenu.h"
59 #include "FUi_DragAndDropItem.h"
60 #include "FUiCtrl_Edit.h"
61 #include "FUiCtrl_EditCopyPasteManager.h"
62 #include "FUiCtrl_EditPresenter.h"
63 #include "FUiCtrl_TokenEditPresenter.h"
64 #include "FUiCtrl_FlickAnimation.h"
65 #include "FUiCtrl_Frame.h"
66 #include "FUiCtrl_Form.h"
67 #include "FUiCtrl_Scroll.h"
68 #include "FUiCtrl_ScrollPanel.h"
69 #include "FUiCtrl_Toolbar.h"
70 #include "FUiCtrl_TableView.h"
71 #include "FUi_Window.h"
72
73 #define EDIT_DRAG_AND_DROP_ENABLED 0
74
75 using namespace Tizen::Base::Runtime;
76 using namespace Tizen::Base::Utility;
77 using namespace Tizen::Media;
78 using namespace Tizen::Ui::Animations;
79 using namespace Tizen::Graphics;
80 using namespace Tizen::Ui;
81 using namespace Tizen::Ui::Controls;
82 using namespace Tizen::Base;
83 using namespace Tizen::Base::Utility;
84 using namespace Tizen::Base::Collection;
85 using namespace Tizen::Locales;
86 using namespace Tizen::Graphics::_Text;
87
88 namespace Tizen { namespace Ui { namespace Controls
89 {
90 const int EDIT_PASSWORD_TIMER_PERIOD = 1000;
91 const int EDIT_CURSOR_TIMER_PERIOD = 600;
92 const int MAX_LINE_NUMBER = 100;
93 const int MAX_FLEXIBLE_HEIGHT_VERTICAL_MODE = 4000;
94 const int MAX_FLEXIBLE_HEIGHT_HORIZONTAL_MODE = 2500;
95 const int EDIT_FLICK_SCROLL_TIMER_INTERVAL = 10;
96 const int EDIT_FLICK_SCROLL_MOVE_AMOUNT_MULTIPLIER = 2;
97 const float DIRECTION_DECISION_RATIO = 1.3f;
98 const float HORIZONTAL_DECISION_RATIO = 1.5f;
99 const float MOVE_SKIP_DECISION_RANGE = 5.0f;
100 const int TITLE_SLIDING_TIME = 800;
101
102 const int LANGUAGE_CODE_START = 0;
103 const int LANGUAGE_CODE_MAX = 2;
104
105 bool _EditPresenter::__isKeypadExist = false;
106 bool _EditPresenter::__isClipboardExist = false;
107 float _EditPresenter::__initialParentHeight = 0.0f;
108 float _EditPresenter::__clipboardHeight = 0.0f;
109 _EditFooterVisibleStatus _EditPresenter::__initialFooterVisibleStatus = EDIT_FOOTER_VISIBLE_STATUS_NONE;
110 bool _EditPresenter::__footerVisibleChanged = false;
111 unsigned int _EditPresenter::__latestBoundedContext = null;
112 const float _EditPresenter::TOUCH_PRESS_THRESHOLD_IN_CLEAR_AREA = 0.04f;
113 _ScrollPanel* _EditPresenter::__pResizedPanel = null;
114
115
116 class _EditDragAndDropWindow
117         : public Tizen::Ui::_Window
118 {
119 public:
120         _EditDragAndDropWindow(void);
121         virtual ~_EditDragAndDropWindow(void);
122
123         virtual result OnAttachedToMainTree(void);
124         void SetLabel(_Label* pLabel);
125 private:
126         _Label* __pLabel;
127 }; // _EditDragAndDropWindow
128
129 _EditDragAndDropWindow::_EditDragAndDropWindow(void)
130 : __pLabel(null)
131 {
132 }
133
134 _EditDragAndDropWindow::~_EditDragAndDropWindow(void)
135 {
136         if (__pLabel)
137         {
138                 DetachChild(*__pLabel);
139                 delete __pLabel;
140                 __pLabel = null;
141         }
142 }
143
144 result
145 _EditDragAndDropWindow::OnAttachedToMainTree(void)
146 {
147         AcquireHandle();
148
149         return E_SUCCESS;
150 }
151
152 void
153 _EditDragAndDropWindow::SetLabel(_Label* pLabel)
154 {
155         __pLabel = pLabel;
156 }
157
158 _EditPresenter::_EditPresenter(void)
159         : __pTitleSlidingTimer(null)
160         , __pEdit(null)
161         , __pTextBuffer(null)
162         , __pTextString(null)
163         , __pEditModel(null)
164         , __pScrollBar(null)
165         , __pScrollEffect(null)
166         , __limitLength(0)
167         , __horizontalAlignment(ALIGNMENT_LEFT)
168         , __horizontalAlignmentForBidi(ALIGNMENT_LEFT)
169         , __isScrollBarVisible(false)
170         , __scrollBarBounds()
171         , __initialBounds()
172         , __previousScrollBarPos(0.0f)
173         , __previousScrollBarMaxPos(0.0f)
174         , __pActionEventListener(null)
175         , __pCursorTimer(null)
176         , __pFlickAnimationTimer(null)
177         , __pPasswordTimer(null)
178         , __pFont(null)
179         , __pCursorVisualElement(null)
180         , __pDragAndDropCueVisualElement(null)
181         , __pTextVisualElement(null)
182         , __pTitleTextVisualElement(null)
183         , __pCopyPasteManager(null)
184         , __pFlickAnimation(null)
185         , __pParentForm(null)
186         , __pFullscreenKeypad(null)
187         , __pParentPanel(null)
188         , __pCommandButton(null)
189         , __pInputConnection(null)
190         , __isInputConnectionBound(false)
191         , __sentKeypadEvent(CORE_KEYPAD_EVENT_STATUS_CLOSE)
192         , __pClipboard(null)
193         , __guideText()
194         , __titleText()
195         , __pressedPoint()
196         , __isCopyPastePopupMoving(false)
197         , __pressedAbsolutePoint()
198         , __clearIconBounds()
199         , __textBoxBounds()
200         , __textObjectBounds()
201         , __titleBounds()
202         , __clientBounds()
203         , __previousCursorBounds()
204         , __keypadBounds(0.0f, 0.0f, 0.0f,0.0f)
205         , __pTextObject(null)
206         , __pGuideTextObject(null)
207         , __pTitleTextObject(null)
208         , __titleSlidingAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT)
209         , __textObjectWrap(TEXT_OBJECT_WRAP_TYPE_WORD)
210         , __isTextBlocked(false)
211         , __isGuideTextColorChanged(false)
212         , __isKeypadCommandButtonVisible(false)
213         , __isKeypadCommandButtonUserSetting(false)
214         , __isTextComposing(false)
215         , __isCopyPasteManagerExist(false)
216         , __isCursorChanged(false)
217         , __isCursorInitialized(false)
218         , __isCursorDisabled(false)
219         , __isInitialized(false)
220         , __isMovingCursorByTouchMove(false)
221         , __isTouchMoving(false)
222         , __isTouchPressed(false)
223         , __isClearIconPressed(false)
224         , __isClearIconVisible(false)
225         , __isCursorOpaque(false)
226         , __isTouchReleaseSkipped(false)
227         , __isViewerModeEnabled(false)
228         , __isKeypadNormalNumberStyleEnabled(false)
229         , __isTextCompositionFinished(false)
230         , __isFlexibleHeightFrozen(false)
231         , __isKeypadShowing(false)
232         , __isKeypadHiding(false)
233         , __resizedByKeypadHide(false)
234         , __blockStartPos(0)
235         , __cursorPos(0)
236         , __prevTotalTextHeight(-1.0f)
237         , __textLength(0)
238         , __composingTextLength(0)
239         , __titleWidth(-1.0f)
240         , __verticalMargin(-1.0f)
241         , __isUSBKeyboardConnected(false)
242         , __rotated(false)
243         , __isCutLinkParserEnabled(false)
244         , __echoChar('*')
245         , __ContentTextStatus(EDIT_TEXT_STATUS_COMPOSE_NON)
246         , __isAutoShrinkEnabled(false)
247         , __groupStyle(GROUP_STYLE_NONE)
248         , __isFontInitialized(false)
249         , __contentFontSize(0.0f)
250         , __titleFontSize(0.0f)
251         , __defaultTouchMoveThreshold(0.16f)
252         , __contentFontStyle(FONT_STYLE_PLAIN)
253         , __contentTextStyle(TEXT_BOX_TEXT_STYLE_NORMAL)
254         , __titleFontFaceName("")
255         , __isSearchBar(false)
256         , __pCurrentFrame(null)
257         , __pTextFilter(null)
258         , __textBlockMoveLeft(false)
259         , __textBlockMoving(false)
260         , __clipboardConnected(false)
261         , __updateInitialBounds(true)
262         , __blockTextColor(Color(0, 0, 0))
263         , __rowCursorIndex(-1)
264         , __columnCursorIndex(-1)
265         , __isPasswordVisible(false)
266         , __needToCreateCopyPastePopup(false)
267         , __calculatedCursorBounds(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
268         , __dragAndDropStarted(false)
269         , __dragAndDropString("")
270         , __isTouchLongPressed(false)
271 {
272 }
273
274 void
275 _EditPresenter::OnInputConnectionPanelShowStateChanged(InputConnection& source, InputPanelShowState showState)
276  {
277         if (showState == INPUT_PANEL_SHOW_STATE_SHOW)// 1. keypad show 2.usb on&predictive window show
278         {
279                 __isKeypadHiding = false;
280                 __isKeypadShowing = false;
281                 __isKeypadExist = true;
282
283                 CheckUSBKeyboardStatus();
284
285                 SysLog(NID_UI_CTRL, "INPUT_PANEL_SHOW_STATE_SHOW[Target:%x][Bound:%d][Usb mode:%d]", this, __isInputConnectionBound, __isUSBKeyboardConnected);
286
287                 if (__isInputConnectionBound)
288                 {
289                         if (__isKeypadCommandButtonVisible && __pCommandButton)
290                         {
291                                 SetFooterVisible(false);
292                         }
293
294                         ChangeLayoutInternal(__pEdit->GetOrientation());
295                         AdjustParentPanelHeight(false);
296
297                         ScrollPanelToCursorPosition();
298
299                         if (__isCopyPasteManagerExist)
300                         {
301                                 __pCopyPasteManager->CreateCopyPastePopup();
302                                 __pCopyPasteManager->Show();
303                         }
304                 }
305
306                 if (!__pEdit->IsFullScreenKeypadEdit())
307                 {
308                         if (__pParentForm)
309                         {
310                                 __pParentForm->Draw();
311                         }
312                 }
313
314                 if (__isUSBKeyboardConnected && (__isKeypadCommandButtonVisible && __pCommandButton))
315                 {
316                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
317                 }
318                 else if (__isKeypadCommandButtonVisible && __pCommandButton &&  __pCommandButton->GetVisibleState())//already command exist in usb mode
319                 {
320                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
321                 }
322                 else
323                 {
324                         if (GetLastSentKeypadEvent() != CORE_KEYPAD_EVENT_STATUS_OPEN)
325                         {
326                                 if (!__isClipboardExist)
327                                 {
328                                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_OPEN);
329                                 }
330                                 __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_OPENED);
331                         }
332                 }
333         }
334         else if (showState == INPUT_PANEL_SHOW_STATE_HIDE)// 1.unbound  2.bounded&usb off -> usb on 3.Flick keypad hide
335         {
336                 __isKeypadHiding = false;
337
338                 CheckUSBKeyboardStatus();
339                 SysLog(NID_UI_CTRL, "INPUT_PANEL_SHOW_STATE_HIDE[Target:%x][Bound:%d][Usb mode:%d]", this, __isInputConnectionBound, __isUSBKeyboardConnected);
340
341                 __isKeypadExist = false;
342
343                 if (__resizedByKeypadHide)
344                 {
345                         __resizedByKeypadHide = false;
346                         return;
347                 }
348
349                 if (__isCopyPasteManagerExist)
350                 {
351                         InitializeCopyPasteManager();
352                         __pTextObject->SetBlock(false);
353                         __isTextBlocked = false;
354                 }
355
356                 if (__isInputConnectionBound && __isUSBKeyboardConnected) // hide callback from external condition(usb mode off->on), focus remaining
357                 {
358                         if (!__isKeypadCommandButtonVisible && !__isClipboardExist)
359                         {
360                                 if (__footerVisibleChanged)
361                                 {
362                                         SetFooterVisible(true);// must be called ahead of DeflateClientRectHeight
363                                 }
364                         }
365
366                         ChangeLayoutInternal(__pEdit->GetOrientation());
367
368                         if (__isClipboardExist)
369                         {
370                                 AdjustParentPanelHeight(false);
371                         }
372                         else
373                         {
374                                 AdjustParentPanelHeight(true);
375                         }
376
377                         if (!__pEdit->IsFullScreenKeypadEdit())
378                         {
379                                 if (__pParentForm)
380                                 {
381                                         __pParentForm->Draw();
382                                 }
383                         }
384                 }
385                 else
386                 {
387                         if (__isInputConnectionBound)// keypad hided by back key or prediction hided by usb mode changed(on -> off)
388                         {
389                                 if (!__isKeypadCommandButtonVisible && !__isClipboardExist)
390                                 {
391                                         if (__footerVisibleChanged)
392                                         {
393                                                 SetFooterVisible(true);// must be called ahead of DeflateClientRectHeight
394                                         }
395                                 }
396
397                                 FinishTextComposition();
398
399                                 ChangeLayoutInternal(__pEdit->GetOrientation());
400
401                                 if (__isClipboardExist)
402                                 {
403                                         AdjustParentPanelHeight(false);
404                                 }
405                                 else
406                                 {
407                                         AdjustParentPanelHeight(true);
408                                 }
409
410                                 if (!__pEdit->IsFullScreenKeypadEdit())
411                                 {
412                                         if (__pParentForm)
413                                         {
414                                                 __pParentForm->Draw();
415                                         }
416                                 }
417                         }
418                         else// called by focus move or HideKeypad() api call
419                         {
420                                 if (__pCommandButton && __isKeypadCommandButtonVisible)
421                                 {
422                                         SetFooterVisible(true);// must be called ahead of DeflateClientRectHeight
423                                         __pCommandButton->SetVisibleState(false);
424                                         __pCommandButton->Invalidate();
425                                 }
426
427                                 __isInputConnectionBound = false;
428
429                                 AdjustParentPanelHeight(true);
430
431                                 if (__pParentForm)
432                                 {
433                                         SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
434                                         __pParentForm->DeflateClientRectHeight(0.0f);
435                                 }
436
437                                 if (!__pEdit->IsFullScreenKeypadEdit())
438                                 {
439                                         if (__pParentForm)
440                                         {
441                                                 __pParentForm->Draw();
442                                         }
443                                 }
444                         }
445                 }
446
447                 if ((__isKeypadCommandButtonVisible && __pCommandButton) && __isInputConnectionBound)
448                 {
449                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
450                 }
451                 else if((__isUSBKeyboardConnected && (__isKeypadCommandButtonVisible &&__pCommandButton) && !__isInputConnectionBound) ||
452                                 (__isUSBKeyboardConnected && __isClipboardExist))
453                 {
454                         //do nothing
455                 }
456                 else
457                 {
458                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CLOSED);
459                         __pEdit->DetachScrollPanelEvent();
460
461                         if (!__isClipboardExist)
462                         {
463                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CLOSE);
464                         }
465                 }
466         }
467
468         return;
469  }
470
471 void
472 _EditPresenter::OnInputConnectionPanelLanguageChanged(InputConnection& source, LanguageCode language)
473 {
474         LanguageCode oldLanguageCode;
475         __pEditModel->GetCurrentLanguage(oldLanguageCode);
476
477         __pEditModel->SetCurrentLanguage(language);
478         __pEdit->SendLanguageEvent(oldLanguageCode, language);
479
480         return;
481 }
482
483 void
484 _EditPresenter::OnInputConnectionPanelBoundsChanged(InputConnection& source, const Rectangle& bounds)
485 {
486         float previousHeight = __keypadBounds.height;
487
488         CheckUSBKeyboardStatus();
489
490         if ((__isUSBKeyboardConnected == false) && __isKeypadExist == false)
491         {
492                 SysLog(NID_UI_CTRL, "OnInputConnectionPanelBoundsChanged skipped - __isUSBKeyboardConnected:(%), __isKeypadExist:(%d)", __isUSBKeyboardConnected, __isKeypadExist);
493                 return;
494         }
495
496         if (CheckKeypadExist(__pEdit->GetOrientation()) == false)//double check keypad Exist
497         {
498                 SysLog(NID_UI_CTRL, "OnInputConnectionPanelBoundsChanged skipped - Keypad doesn't exist!!");
499                 return;
500         }
501         else
502         {
503                 if (IsKeypadRotating(__pEdit->GetOrientation()))
504                 {
505                         SysLog(NID_UI_CTRL, "OnInputConnectionPanelBoundsChanged skipped - Keypad is rotating!!");
506                         AdjustParentPanelHeight(true);
507                         return;
508                 }
509         }
510
511         SysLog(NID_UI_CTRL, "OnInputConnectionPanelBoundsChanged");
512         ChangeLayoutInternal(__pEdit->GetOrientation());
513         AdjustParentPanelHeight(false);
514         ScrollPanelToCursorPosition();
515
516         if (__pParentForm)
517         {
518                 __pParentForm->Draw();
519         }
520
521         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
522
523         if (__isCopyPasteManagerExist)
524         {
525                 DrawText();
526                 if (__pCopyPasteManager->GetCopyPastePopup())
527                 {
528                         if (previousHeight != bounds.height)
529                         {
530                                 __pCopyPasteManager->CreateCopyPastePopup();
531                         }
532                 }
533                 __pCopyPasteManager->Show();
534         }
535
536         return;
537 }
538
539 void
540 _EditPresenter::OnInputConnectionTextPredictionShowStateChanged(InputConnection& source, bool isShown)
541 {
542         return;
543 }
544
545 void
546 _EditPresenter::OnInputConnectionTextPredictionBoundsChanged(InputConnection& source, const Rectangle& bounds)
547 {
548         return;
549 }
550
551 void
552 _EditPresenter::OnInputConnectionTextCommitted(InputConnection& source, const String& committedText)
553 {
554         OnTextCommitted(committedText);
555
556         return;
557 }
558
559 void
560 _EditPresenter::OnTextCommitted(const String& commitText)
561 {
562         bool isTextComposingFinished = false;
563         char enterText1[2] = {'\n', };
564         char enterText2[2] = {'\r', };
565
566         if (IsViewModeEnabled() == true)
567         {
568                 return;
569         }
570
571         if (IsBlocked() == true)
572         {
573                 CoreKeypadAction keypadaction = GetKeypadAction();
574                 if (keypadaction == CORE_KEYPAD_ACTION_ENTER || !(commitText == enterText1 || commitText == enterText2))
575                 {
576                         int start = 0;
577                         int end = 0;
578                         GetBlockRange(start, end);
579                         __isFlexibleHeightFrozen = true;
580                         DeleteText(start, end);
581                         __isFlexibleHeightFrozen = false;
582                         ReleaseTextBlock();
583                 }
584         }
585
586         if (__isCopyPasteManagerExist)
587         {
588                 InitializeCopyPasteManager();
589         }
590
591         int textLength = commitText.GetLength();
592         int compositionStart = __cursorPos - textLength;
593
594         if (__isTextComposing == true)
595         {
596                 __isFlexibleHeightFrozen = true;
597                 DeleteText(__cursorPos-__composingTextLength, __cursorPos);
598                 __isFlexibleHeightFrozen = false;
599
600                 __isTextComposing = false;
601                 __composingTextLength = 0;
602                 isTextComposingFinished = true;
603         }
604
605         if (__ContentTextStatus != EDIT_TEXT_STATUS_COMPOSE_NON)
606         {
607                 __pTextObject->SetFont(__pFont, __cursorPos, __cursorPos+textLength);
608                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
609         }
610
611         if (__pPasswordTimer)
612         {
613                 ChangePasswordToEchoCharacter(__pTextBuffer, __echoChar);
614                 StopPasswordTimer();
615         }
616
617         if (commitText == enterText1 || commitText == enterText2)
618         {
619                 CoreKeypadAction keypadaction = GetKeypadAction();
620
621                 __pEdit->SendKeypadEvent(keypadaction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
622                 if (keypadaction != CORE_KEYPAD_ACTION_ENTER)
623                 {
624                         return;
625                 }
626
627                 if(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
628                 {
629                         DrawText();
630                         return;
631                 }
632         }
633
634         char tapText[2] = {'\t', };
635         if (commitText == tapText)
636         {
637                 return;
638         }
639
640         // Limitation Protect
641         String insetText = commitText;
642         int currentLength = GetTextLength();
643         int totalLength = currentLength + textLength;
644         int excessCharacterLength = totalLength - __limitLength;
645
646         if (excessCharacterLength >= 0)
647         {
648                 textLength -= excessCharacterLength;
649                 if (textLength > 0)
650                 {
651                         insetText.Remove(textLength, excessCharacterLength);
652                 }
653                 else
654                 {
655                         textLength = 0;
656                 }
657         }
658
659         InsertTextAt(__cursorPos, insetText);
660
661         ScrollPanelToCursorPosition();
662
663         if ((__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD) && isTextComposingFinished)
664         {
665                 ReplaceTextIntoPasswordHyphenString();
666         }
667
668         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
669         {
670                 DrawText();
671         }
672
673         ChangePasswordToEchoCharacter((compositionStart + textLength), textLength);
674
675         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
676
677         return;
678 }
679
680 void
681 _EditPresenter::OnInputConnectionComposingTextChanged(InputConnection& source, const String& composingText, int cursorPosition)
682 {
683         OnComposingTextChanged(composingText, cursorPosition);
684
685         return;
686 }
687
688 void
689 _EditPresenter::OnComposingTextChanged(const String& composingText, int cursorPosition)
690 {
691         if (IsViewModeEnabled() == true)
692         {
693                 return;
694         }
695
696         if (IsBlocked() == true)
697         {
698                 int start = 0;
699                 int end = 0;
700                 GetBlockRange(start, end);
701                 __isFlexibleHeightFrozen = true;
702                 DeleteText(start, end);
703                 __isFlexibleHeightFrozen = false;
704                 ReleaseTextBlock();
705         }
706
707         if (__isCopyPasteManagerExist)
708         {
709                 InitializeCopyPasteManager();
710         }
711
712         int textLength = composingText.GetLength();
713
714         if (__isTextComposing == false)
715         {
716                 if (textLength == 0)
717                 {
718                         return;
719                 }
720         }
721         else
722         {
723                 int compositionStart = GetCursorPosition();
724
725                 if (textLength == 0)
726                 {
727                         __isTextComposing = false;
728
729                         // FirstText Check Logic
730                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
731                         int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine);
732                         bool isFirstText = false;
733                         if (firstTextIndex + 1 == __pTextObject->GetCursorIndex())
734                         {
735                                 isFirstText = true;
736                         }
737
738                         DeleteText(compositionStart-__composingTextLength, compositionStart);
739
740                         if (isFirstText)
741                         {
742                                 __isCursorChanged = false;
743                                 AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT);
744                         }
745
746                         __composingTextLength = 0;
747
748                         DrawText();
749
750                         if (!__isCursorChanged)
751                         {
752                                 __isCursorChanged = true;
753                         }
754                         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
755
756                         return;
757                 }
758                 else
759                 {
760                         __isFlexibleHeightFrozen = true;
761                         DeleteText(compositionStart-__composingTextLength, compositionStart);
762                         __isFlexibleHeightFrozen = false;
763                 }
764         }
765
766         __composingTextLength = textLength;
767         if (__composingTextLength > 0)
768         {
769                 __isTextComposing = true;
770         }
771
772         if (__pPasswordTimer)
773         {
774                 ChangePasswordToEchoCharacter(__pTextBuffer, __echoChar);
775                 StopPasswordTimer();
776         }
777
778         // Limitation Protect
779         String insetText = composingText;
780         int currentLength = GetTextLength();
781         int totalLength = currentLength + textLength;
782         int excessCharacterLength = totalLength - __limitLength;
783
784         if (excessCharacterLength >= 0)
785         {
786                 __composingTextLength -= excessCharacterLength;
787                 if (__composingTextLength > 0)
788                 {
789                         insetText.Remove(__composingTextLength, excessCharacterLength);
790                 }
791                 else
792                 {
793                         __composingTextLength = 0;
794                 }
795         }
796
797         _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
798         SysTryReturnVoidResult(NID_UI_CTRL, fontImpl != null, E_SYSTEM, "[E_SYSTEM] fontImpl is null.");
799         fontImpl->SetUnderline(true);
800         __pTextObject->SetFont(__pFont, 0, 0);
801
802         if (__composingTextLength > 0)
803         {
804                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE;
805         }
806
807         InsertTextAt(GetCursorPosition(), insetText);
808
809         fontImpl->SetUnderline(false);// rollback to default content font
810         __pTextObject->SetFont(__pFont, 0, 0);
811
812         ScrollPanelToCursorPosition();
813
814         DrawText();
815         if (__composingTextLength > 0)
816         {
817                 ChangePasswordToEchoCharacter((GetCursorPosition() - __composingTextLength), __composingTextLength);
818         }
819
820         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
821
822         return;
823 }
824
825 void
826 _EditPresenter::DeleteSurroundingText(InputConnection& source, int offset, int charCount)
827 {
828         OnSurroundingTextDeleted(offset, charCount);
829
830         return;
831 }
832
833 void
834 _EditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
835 {
836         int start = 0;
837         int end = 0;
838
839         if (IsBlocked() == true)
840         {
841                 GetBlockRange(start, end);
842         }
843         else
844         {
845                 start = __cursorPos + offset;
846                 if (start < 0)
847                 {
848                    return;
849                 }
850                 end = start + charCount;
851                 if (end > __cursorPos)
852                 {
853                    return;
854                 }
855         }
856
857         DeleteText(start, end);
858
859         if (__isCopyPasteManagerExist)
860         {
861                 InitializeCopyPasteManager();
862         }
863
864         if (IsBlocked() == true)
865         {
866                 ReleaseTextBlock();
867         }
868
869         DrawText();
870
871         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
872
873         return;
874 }
875
876 void
877 _EditPresenter::GetPreviousText(InputConnection& source, String& text, int& cursorPosition)
878 {
879         const int SURRONDING_TEXT_SIZE = 5;
880         int stringLength = 0;
881         String tempString;
882
883         if (__cursorPos == 0)
884         {
885                 text = null;
886                 cursorPosition = 0;
887         }
888         else
889         {
890                 if (__cursorPos < SURRONDING_TEXT_SIZE)
891                 {
892                         text = GetText(0, __cursorPos - 1);
893                 }
894                 else
895                 {
896                         int previousTextSize = 0;
897
898                         for (int index = 0; index < __cursorPos; index++)
899                         {
900                                 previousTextSize++;
901                                 if (__pTextBuffer[__cursorPos-index-1] != 0x20)
902                                 {
903                                         break;
904                                 }
905                         }
906
907                         if (previousTextSize < SURRONDING_TEXT_SIZE)
908                         {
909                                 previousTextSize = SURRONDING_TEXT_SIZE;
910                         }
911
912                         text = GetText(__cursorPos - previousTextSize, __cursorPos - 1);
913                 }
914
915                 stringLength = text.GetLength();
916                 cursorPosition = stringLength;
917         }
918
919         return;
920 }
921
922 void
923 _EditPresenter::OnClipboardPopupOpened(Tizen::Graphics::Dimension& clipboardPopupSize)
924 {
925         FloatDimension floatClipboardPopupSize = _CoordinateSystemUtils::ConvertToFloat(clipboardPopupSize);
926
927         if (__clipboardConnected)
928         {
929                 __isClipboardExist = true;
930                 FloatRectangle absKeypadBounds;
931                 GetKeypadBounds(absKeypadBounds);
932                 CheckUSBKeyboardStatus();
933
934                 __clipboardHeight = floatClipboardPopupSize.height;
935
936                 SysLog(NID_UI_CTRL, "clipboard height = %f, [KeypadExist:%d]keypad height = %f", floatClipboardPopupSize.height, __isKeypadExist, absKeypadBounds.height);
937
938                 if (__isKeypadExist) //resize as difference between clipboard height vs keypad height
939                 {
940                         if (floatClipboardPopupSize.height > absKeypadBounds.height)
941                         {
942                                 ChangeLayoutInternal(__pEdit->GetOrientation());
943                                 AdjustParentPanelHeight(false);
944                                 ScrollPanelToCursorPosition();
945
946                                 if (__pParentForm)
947                                 {
948                                         __pParentForm->Draw();
949                                 }
950
951                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
952                         }
953                 }
954                 else
955                 {
956                         if (!__isKeypadCommandButtonVisible)
957                         {
958                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CREATED);
959
960                                 ChangeLayoutInternal(__pEdit->GetOrientation());
961                                 AdjustParentPanelHeight(false);
962                                 ScrollPanelToCursorPosition();
963
964                                 if (__pParentForm)
965                                 {
966                                         __pParentForm->Draw();
967                                 }
968
969                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_OPEN);
970                         }
971                         else
972                         {
973                                 ChangeLayoutInternal(__pEdit->GetOrientation());
974                                 AdjustParentPanelHeight(false);
975                                 ScrollPanelToCursorPosition();
976
977                                 if (__pParentForm)
978                                 {
979                                         __pParentForm->Draw();
980                                 }
981
982                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
983                         }
984                 }
985                 if (__isCopyPasteManagerExist)
986                 {
987                         UpdateComponentInformation();
988                         __pCopyPasteManager->Show();
989                 }
990         }
991
992         return;
993 }
994
995 void
996 _EditPresenter::OnClipboardPopupBoundsChanged(Tizen::Graphics::Dimension& clipboardPopupSize)
997 {
998         FloatDimension floatClipboardPopupSize = _CoordinateSystemUtils::ConvertToFloat(clipboardPopupSize);
999
1000         if (__clipboardConnected)
1001         {
1002                 FloatRectangle absKeypadBounds;
1003                 GetKeypadBounds(absKeypadBounds);
1004                 CheckUSBKeyboardStatus();
1005
1006                 __clipboardHeight = floatClipboardPopupSize.height;
1007
1008                 SysLog(NID_UI_CTRL, "clipboard height = %f, [KeypadExist:%d]keypad height = %f", floatClipboardPopupSize.height, __isKeypadExist, absKeypadBounds.height);
1009
1010                 if (__isKeypadExist)
1011                 {
1012                         if (floatClipboardPopupSize.height >= absKeypadBounds.height)
1013                         {
1014                                 ChangeLayoutInternal(__pEdit->GetOrientation());
1015                                 AdjustParentPanelHeight(false);
1016                                 ScrollPanelToCursorPosition();
1017
1018                                 if (__pParentForm)
1019                                 {
1020                                         __pParentForm->Draw();
1021                                 }
1022
1023                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1024                         }
1025                         else
1026                         {
1027                                 ChangeLayoutInternal(__pEdit->GetOrientation());
1028                                 AdjustParentPanelHeight(false);
1029                                 ScrollPanelToCursorPosition();
1030
1031                                 if (__pParentForm)
1032                                 {
1033                                         __pParentForm->Draw();
1034                                 }
1035
1036                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1037                         }
1038                 }
1039                 else
1040                 {
1041                         ChangeLayoutInternal(__pEdit->GetOrientation());
1042                         AdjustParentPanelHeight(false);
1043                         ScrollPanelToCursorPosition();
1044
1045                         if (__pParentForm)
1046                         {
1047                                 __pParentForm->Draw();
1048                         }
1049
1050                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1051                 }
1052
1053                 if (__rotated) // Command button should be relocated after rotation in case of no keypad.
1054                 {
1055                         if (__isCopyPasteManagerExist)
1056                         {
1057                                 PostInternalEvent(String(L"ShowCopyPaste"));
1058                         }
1059                         __rotated = false;
1060                 }
1061                 else if (__isCopyPasteManagerExist)
1062                 {
1063                         __pCopyPasteManager->AdjustBounds();
1064                 }
1065         }
1066
1067         return;
1068 }
1069
1070 void
1071 _EditPresenter::OnClipboardPopupClosed(void)
1072 {
1073         if (__clipboardConnected)
1074         {
1075                 if (__isCopyPasteManagerExist)
1076                 {
1077                         InitializeCopyPasteManager();
1078                         __pTextObject->SetBlock(false);
1079                         __isTextBlocked = false;
1080                 }
1081
1082                 if (__pClipboard)
1083                 {
1084                         __pClipboard->HidePopup();
1085                 }
1086
1087                 __isClipboardExist = false;
1088                 FloatRectangle absKeypadBounds;
1089                 GetKeypadBounds(absKeypadBounds);
1090                 CheckUSBKeyboardStatus();
1091
1092                 __clipboardHeight = 0.0f;
1093
1094                 SysLog(NID_UI_CTRL, "clipboard closed! [KeypadExist:%d]keypad height = %f", __isKeypadExist, absKeypadBounds.height);
1095
1096                 if (__isInputConnectionBound)
1097                 {
1098                         ChangeLayoutInternal(__pEdit->GetOrientation());
1099                 }
1100
1101                 if (__isKeypadExist)
1102                 {
1103                         AdjustParentPanelHeight(false);
1104
1105                         if (__pParentForm)
1106                         {
1107                                 __pParentForm->Draw();
1108                         }
1109
1110                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1111                 }
1112                 else
1113                 {
1114                         if (__footerVisibleChanged)
1115                         {
1116                                 SetFooterVisible(true);
1117                         }
1118
1119                         AdjustParentPanelHeight(true);
1120                         if (__pParentForm)
1121                         {
1122                                 SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
1123                                 __pParentForm->DeflateClientRectHeight(0.0f);
1124                                 __pParentForm->Draw();
1125                         }
1126
1127                         if (!__isKeypadCommandButtonVisible)
1128                         {
1129                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CLOSE);
1130                         }
1131                         else
1132                         {
1133                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_BOUNDS_CHANGED);
1134                         }
1135                 }
1136
1137                 __clipboardConnected = false;
1138         }
1139
1140         return;
1141 }
1142
1143 _EditPresenter::~_EditPresenter(void)
1144 {
1145         Dispose();
1146 }
1147
1148 result
1149 _EditPresenter::Dispose(void)
1150 {
1151         if (__pCurrentFrame)
1152         {
1153                 __pCurrentFrame->RemoveFrameEventListener(*this);
1154                 __pCurrentFrame = null;
1155         }
1156
1157         CheckUSBKeyboardStatus();
1158
1159         if(__latestBoundedContext != (unsigned int)this)//context is already chagned.
1160         {
1161                 __isKeypadHiding = false;
1162         }
1163
1164         if (__isInputConnectionBound || __isKeypadHiding || __clipboardConnected) //Edit control removed without FocusLost callback or HideKeypad.
1165         {
1166                 if (__clipboardConnected) //Edit control removed after FocusLost or without FocusLost callback.
1167                 {
1168                         __pClipboard->HidePopup();
1169                         __isClipboardExist = false;
1170                 }
1171
1172                 if (__pCommandButton && __isKeypadCommandButtonVisible)
1173                 {
1174                         __pCommandButton->SetVisibleState(false);
1175
1176                         SetFooterVisible(true);
1177
1178                         delete __pCommandButton;
1179                         __pCommandButton = null;
1180                 }
1181
1182                 if (__pParentForm)
1183                 {
1184                         SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
1185                         __pParentForm->DeflateClientRectHeight(0.0f);
1186                 }
1187
1188                 AdjustParentPanelHeight(true);
1189
1190                 __isKeypadExist = false;
1191
1192                 __latestBoundedContext = null;
1193         }
1194
1195         __initialFooterVisibleStatus = EDIT_FOOTER_VISIBLE_STATUS_NONE;
1196         __footerVisibleChanged = false;
1197
1198         if (__pParentPanel)
1199         {
1200                 __pParentPanel->RemoveScrollEventListener(*__pEdit);
1201         }
1202
1203         if (__pClipboard)
1204         {
1205                 __pClipboard->RemoveClipboardPopupEventListener(*this);
1206         }
1207
1208         if (__pFullscreenKeypad)
1209         {
1210                 __pFullscreenKeypad->Close();
1211                 delete __pFullscreenKeypad;
1212                 __pFullscreenKeypad = null;
1213         }
1214
1215         delete __pScrollEffect;
1216         __pScrollEffect = null;
1217
1218         if (__pTextBuffer)
1219         {
1220                 delete[] __pTextBuffer;
1221                 __pTextBuffer = null;
1222         }
1223
1224         delete __pTextString;
1225         __pTextString = null;
1226
1227         delete __pEditModel;
1228         __pEditModel = null;
1229
1230         if (__pCursorTimer)
1231         {
1232                 __pCursorTimer->Cancel();
1233                 delete __pCursorTimer;
1234                 __pCursorTimer = null;
1235         }
1236
1237         if (__pInputConnection)
1238         {
1239                 delete __pInputConnection;
1240                 __pInputConnection = null;
1241         }
1242
1243         delete __pTextObject;
1244         __pTextObject = null;
1245
1246         delete __pGuideTextObject;
1247         __pGuideTextObject = null;
1248
1249         delete __pTitleTextObject;
1250         __pTitleTextObject = null;
1251
1252         if (__pPasswordTimer)
1253         {
1254                 __pPasswordTimer->Cancel();
1255                 delete __pPasswordTimer;
1256                 __pPasswordTimer = null;
1257         }
1258
1259         if (__pScrollBar != null && __pEdit != null)
1260         {
1261                 __pEdit->DetachSystemChild(*__pScrollBar);
1262                 delete __pScrollBar;
1263                 __pScrollBar = null;
1264         }
1265
1266         if (__pFlickAnimationTimer)
1267         {
1268                 __pFlickAnimationTimer->Cancel();
1269                 delete __pFlickAnimationTimer;
1270                 __pFlickAnimationTimer = null;
1271         }
1272
1273         if (__pTitleSlidingTimer)
1274         {
1275                 __pTitleSlidingTimer->Cancel();
1276                 delete  __pTitleSlidingTimer;
1277                 __pTitleSlidingTimer = null;
1278         }
1279
1280         delete __pFlickAnimation;
1281         __pFlickAnimation = null;
1282
1283         if (__pCopyPasteManager != null)
1284         {
1285                 delete __pCopyPasteManager;
1286                 __pCopyPasteManager = null;
1287         }
1288
1289         if (__pTextVisualElement)
1290         {
1291                 __pTextVisualElement->Destroy();
1292                 __pTextVisualElement = null;
1293         }
1294
1295         if (__pCursorVisualElement)
1296         {
1297                 __pCursorVisualElement->Destroy();
1298                 __pCursorVisualElement = null;
1299         }
1300
1301         if (__pDragAndDropCueVisualElement)
1302         {
1303                 __pDragAndDropCueVisualElement->Destroy();
1304                 __pDragAndDropCueVisualElement = null;
1305         }
1306
1307         if (__pTitleTextVisualElement)
1308         {
1309                 __pTitleTextVisualElement->Destroy();
1310                 __pTitleTextVisualElement = null;
1311         }
1312
1313         return E_SUCCESS;
1314 }
1315
1316 bool
1317 _EditPresenter::IsKeypadExist(void) const
1318 {
1319         return __isKeypadExist;
1320 }
1321
1322 bool
1323 _EditPresenter::IsClipboardExist(void) const
1324 {
1325         return __isClipboardExist;
1326 }
1327
1328 void
1329 _EditPresenter::CheckUSBKeyboardStatus(void)
1330 {
1331         if (__pInputConnection->CheckUSBKeyboardStatus())
1332         {
1333                 __isUSBKeyboardConnected = true;
1334         }
1335         else
1336         {
1337                 __isUSBKeyboardConnected = false;
1338         }
1339
1340         return;
1341 }
1342
1343 bool
1344 _EditPresenter::IsUsbKeyboardConnected(void) const
1345 {
1346         if (__pInputConnection->CheckUSBKeyboardStatus())
1347         {
1348                 return true;
1349         }
1350         else
1351         {
1352                 return false;
1353         }
1354 }
1355
1356 bool
1357 _EditPresenter::IsCurrentFocused(void)
1358 {
1359         _ControlManager* pControlManager = _ControlManager::GetInstance();
1360
1361         if (pControlManager)
1362         {
1363                 _Control* pControl = pControlManager->GetFocusControl();
1364                 if (pControl != __pEdit)
1365                 {
1366                         return false;
1367                 }
1368                 else
1369                 {
1370                         return true;
1371                 }
1372         }
1373         else
1374         {
1375                 return __pEdit->IsInternalFocused();
1376         }
1377 }
1378
1379 bool
1380 _EditPresenter::InitializeFocusedCondition(void)
1381 {
1382         if (!__pParentForm)
1383         {
1384                 __pParentForm = GetParentForm();
1385
1386                 if (!__pParentForm && __isKeypadCommandButtonVisible)
1387                 {
1388                         __isKeypadCommandButtonVisible = false;
1389                 }
1390         }
1391
1392         if (!__pTextVisualElement)
1393         {
1394                 result r = E_SUCCESS;
1395                 __pTextVisualElement = new (std::nothrow) _VisualElement;
1396                 SysTryReturn(NID_UI_CTRL, __pTextVisualElement != null, false, E_OUT_OF_MEMORY, "Memory allocation failed.");
1397
1398                 r = __pTextVisualElement->Construct();
1399                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
1400
1401                 __pTextVisualElement->SetSurfaceOpaque(false);
1402                 __pTextVisualElement->SetImplicitAnimationEnabled(false);
1403
1404                 __pTextVisualElement->SetShowState(true);
1405
1406                 _VisualElement* pEditVisualElement = __pEdit->GetVisualElement();
1407                 SysTryCatch(NID_UI_CTRL, pEditVisualElement, , r = E_SYSTEM, "[E_SYSTEM] Unable to get root visual element.");
1408
1409                 pEditVisualElement->AttachChild(*__pTextVisualElement);
1410                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add child", GetErrorMessage(r));
1411         }
1412
1413         __isCursorOpaque = true;
1414
1415         return true;
1416
1417 CATCH:
1418         __pTextVisualElement->Destroy();
1419         __pTextVisualElement = null;
1420
1421         return false;
1422 }
1423
1424 void
1425 _EditPresenter::SetSentKeypadEvent(CoreKeypadEventStatus sentKeypadEvent)
1426 {
1427         __sentKeypadEvent = sentKeypadEvent;
1428 }
1429
1430 CoreKeypadEventStatus
1431 _EditPresenter::GetLastSentKeypadEvent(void)
1432 {
1433         return __sentKeypadEvent;
1434 }
1435
1436
1437 _EditPresenter*
1438 _EditPresenter::CreateInstanceN(void)
1439 {
1440         _EditPresenter* pPresenter = new (std::nothrow) _EditPresenter;
1441         if (pPresenter == null)
1442         {
1443                 SetLastResult(E_OUT_OF_MEMORY);
1444                 return null;
1445         }
1446
1447         return pPresenter;
1448 }
1449
1450 result
1451 _EditPresenter::Initialize(const _Control& control)
1452 {
1453         result r = E_SUCCESS;
1454         _EditModel* pEditModel = null;
1455         _VisualElement* pEditVisualElement = null;
1456         TextSimple* pSimpleText = null;
1457         _ControlManager* pControlManager = _ControlManager::GetInstance();
1458         _Window* pWindow = null;
1459
1460         __pEdit = dynamic_cast<_Edit*>(const_cast<_Control*>(&control));
1461         SysAssertf(__pEdit != null, "__pEdit is null");
1462
1463         __pTextObject = new (std::nothrow) TextObject;
1464         if (__pTextObject == null)
1465         {
1466                 r = E_OUT_OF_MEMORY;
1467                 goto CATCH;
1468         }
1469
1470         __pTextObject->Construct();
1471         pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1472         __pTextObject->AppendElement(*pSimpleText);
1473
1474         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
1475         {
1476                 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1477                 if (__pEdit->IsFullScreenKeypadEdit())
1478                 {
1479                         __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_TOP);
1480                 }
1481                 else
1482                 {
1483                         __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1484                 }
1485                 __pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1486                 __textObjectWrap = TEXT_OBJECT_WRAP_TYPE_NONE;
1487         }
1488         else
1489         {
1490                 __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_TOP);
1491                 __pTextObject->SetWrap(__textObjectWrap);
1492         }
1493
1494         __pTextString = new (std::nothrow) String;
1495         SysTryCatch(NID_UI_CTRL, __pTextString, , r = E_OUT_OF_MEMORY, "Memory allocation failed.");
1496         __limitLength = 0;
1497
1498         if (__pFont == null)
1499         {
1500                 _ControlOrientation orientation = __pEdit->GetOrientation();
1501                 float defaultFontSize = 0.0f;
1502                 GET_SHAPE_CONFIG(EDIT::DEFAULT_FONT_SIZE, orientation, defaultFontSize);
1503
1504                 __contentFontSize = defaultFontSize;
1505                 __contentFontStyle = FONT_STYLE_PLAIN;
1506
1507                 __pFont = __pEdit->GetFallbackFont();
1508
1509                 r = GetLastResult();
1510                 SysTryReturn(NID_UI_CTRL, __pFont, r, r, "[%s] Propagating.", GetErrorMessage(r));
1511
1512                 __titleFontFaceName = __pFont->GetFaceName();
1513
1514                 __isFontInitialized = true;
1515                 __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
1516                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
1517         }
1518
1519         __pScrollEffect = new (std::nothrow) _EditScrollEffectInfo;
1520         SysTryCatch(NID_UI_CTRL, __pScrollEffect, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1521
1522         for (int i = 0; i < EDIT_SCROLLFRAME_MAX; i++)
1523         {
1524                 __pScrollEffect->touchScrollFrameLevel[i] = 2 + i;
1525         }
1526
1527         __pScrollEffect->previousY = -1.0f;
1528         __pScrollEffect->currentY = -1.0f;
1529         __pScrollEffect->previousX = -1.0f;
1530         __pScrollEffect->currentX = -1.0f;
1531         __pScrollEffect->previousAbsX = -1.0f;
1532         __pScrollEffect->currentAbsX = -1.0f;
1533         __pScrollEffect->previousAbsY = -1.0f;
1534         __pScrollEffect->currentAbsY = -1.0f;
1535         __pScrollEffect->cursorPosition = -1;
1536
1537         pEditModel = new (std::nothrow) _EditModel;
1538         SysTryCatch(NID_UI_CTRL, pEditModel, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1539
1540         SetModel(*pEditModel);
1541
1542         SetClientBounds();
1543         SetInitialBounds();
1544
1545         if (__pEdit->GetEditStyle() & EDIT_STYLE_VIEWER)
1546         {
1547                 SetViewModeEnabled(true);
1548                 __isCutLinkParserEnabled = true;
1549         }
1550         else
1551         {
1552                 SetKeypadEnabled(true);
1553                 __isCutLinkParserEnabled = false;
1554         }
1555
1556         if (__pEdit->GetInputStyle() == INPUT_STYLE_FULLSCREEN)
1557         {
1558                 SetCursorDisabled(true);
1559         }
1560
1561         __initialBounds = __pEdit->GetBoundsF();
1562
1563         __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
1564
1565         __pCursorVisualElement = new (std::nothrow) _VisualElement;
1566         SysTryCatch(NID_UI_CTRL, __pCursorVisualElement, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1567
1568         r = __pCursorVisualElement->Construct();
1569         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
1570
1571         __pCursorVisualElement->SetSurfaceOpaque(false);
1572         __pCursorVisualElement->SetImplicitAnimationEnabled(false);
1573
1574         __pDragAndDropCueVisualElement = new (std::nothrow) _VisualElement;
1575         SysTryCatch(NID_UI_CTRL, __pDragAndDropCueVisualElement, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1576
1577         r = __pDragAndDropCueVisualElement->Construct();
1578         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
1579
1580         __pDragAndDropCueVisualElement->SetSurfaceOpaque(false);
1581         __pDragAndDropCueVisualElement->SetImplicitAnimationEnabled(false);
1582
1583         pEditVisualElement = __pEdit->GetVisualElement();
1584         SysTryCatch(NID_UI_CTRL, pEditVisualElement, , r = E_SYSTEM, "[E_SYSTEM] Unable to get root visual element.");
1585
1586         __pCursorVisualElement->SetShowState(true);
1587         __pDragAndDropCueVisualElement->SetShowState(false);
1588
1589         r = pEditVisualElement->AttachChild(*__pCursorVisualElement);
1590         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add child", GetErrorMessage(r));
1591
1592         r = pEditVisualElement->AttachChild(*__pDragAndDropCueVisualElement);
1593         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add child", GetErrorMessage(r));
1594
1595         __pInputConnection = _InputConnectionImpl::CreateInputConnectionImplN(null);
1596         SysTryCatch(NID_UI_CTRL, __pInputConnection, , r = E_SYSTEM, "[E_SYSTEM] Unable to create an instance .");
1597
1598         __pInputConnection->Initialize(*__pEdit, *this, *this);
1599
1600         __pTextObject->SetBounds(__textObjectBounds);
1601         __pTextObject->HideRearSpace(TEXT_OBJECT_SPACE_HIDE_TYPE_NONE);
1602
1603         pWindow = pControlManager->GetCurrentFrame();
1604         if (pWindow)
1605         {
1606                 __pCurrentFrame = dynamic_cast<_Frame*>(pWindow);
1607                 if (__pCurrentFrame)
1608                 {
1609                         __pCurrentFrame->AddFrameEventListener(*this);
1610                 }
1611         }
1612
1613         __pClipboard = _Clipboard::GetInstance();
1614
1615         if (__pClipboard)
1616         {
1617                 __pClipboard->AddClipboardPopupEventListener(*this);
1618         }
1619
1620         return r;
1621
1622 CATCH:
1623         Dispose();
1624         return r;
1625 }
1626
1627 result
1628 _EditPresenter::InitializeAtFirstDrawing(void)
1629 {
1630         result r = E_SUCCESS;
1631
1632         Resize();
1633
1634         InitializeParentPanel();
1635
1636         AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT);
1637
1638         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false && (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE))
1639         {
1640                 AdjustFlexibleHeight();
1641         }
1642
1643         ReplaceTextIntoPasswordHyphenString();
1644
1645         if (__pEdit->IsViewModeEnabled())
1646         {
1647                 __pEdit->SetCursorPosition(0);
1648         }
1649
1650         __isInitialized = true;
1651
1652         return r;
1653 }
1654
1655 result
1656 _EditPresenter::DrawBackgroundBitmap(Canvas& canvas, bool focused)
1657 {
1658         if (!DrawChangeableBackground(canvas, focused, 0, 0))
1659         {
1660                 return E_SYSTEM;
1661         }
1662
1663         return E_SUCCESS;
1664 }
1665
1666 result
1667 _EditPresenter::DrawChangeableBackground(Canvas& canvas, bool focused, int bitmapId, int effectBitmapId, bool outLine, int outlineBitmapId)
1668 {
1669         result r = E_SUCCESS;
1670         FloatRectangle editRect(0.0f, 0.0f, __pEdit->GetBoundsF().width, __pEdit->GetBoundsF().height);
1671         Color bitmapColor;
1672         Bitmap* pEditBgBitmap = null;
1673         Bitmap* pEditBgEffectBitmap = null;
1674         Bitmap* pReplacementColorBackgroundBitmap = null;
1675         bool borderRoundEnable =  __pEdit->IsBorderRoundStyleEnabled();
1676         EditStatus editStatus = GetCurrentStatus();
1677
1678         pEditBgBitmap = __pEdit->GetDefaultBackgroundBitmap(editStatus);
1679
1680         if (borderRoundEnable)
1681         {
1682                 pEditBgBitmap = null;
1683                 r = GET_BITMAP_CONFIG_N(EDIT::BG_ROUND_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pEditBgBitmap);
1684                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Failed to load bitmap");
1685         }
1686
1687         bitmapColor = __pEdit->GetColor(editStatus);
1688         if (__groupStyle != GROUP_STYLE_NONE)
1689         {
1690                 GET_COLOR_CONFIG(PANEL::GROUPED_STYLE_BG_NORMAL, bitmapColor);
1691         }
1692
1693         pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pEditBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), bitmapColor);
1694         if (pReplacementColorBackgroundBitmap)
1695         {
1696                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
1697                 {
1698                         canvas.DrawNinePatchedBitmap(editRect, *pReplacementColorBackgroundBitmap);
1699                 }
1700                 else
1701                 {
1702                         canvas.DrawBitmap(editRect, *pReplacementColorBackgroundBitmap);
1703                 }
1704         }
1705
1706         if ((!__pEdit->IsFullScreenKeypadEdit() && __groupStyle != GROUP_STYLE_NONE) || GetSearchBarFlag())
1707         {
1708                 pEditBgEffectBitmap = __pEdit->GetDefaultBackgroundEffectBitmap();
1709
1710                 if (pEditBgEffectBitmap)
1711                 {
1712                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pEditBgEffectBitmap))
1713                         {
1714                                 canvas.DrawNinePatchedBitmap(editRect, *pEditBgEffectBitmap);
1715                         }
1716                         else
1717                         {
1718                                 canvas.DrawBitmap(editRect, *pEditBgEffectBitmap);
1719                         }
1720                 }
1721         }
1722
1723         if (borderRoundEnable)
1724         {
1725                 if (pEditBgBitmap)
1726                 {
1727                         delete pEditBgBitmap;
1728                         pEditBgBitmap = null;
1729                 }
1730
1731                 if (pEditBgEffectBitmap)
1732                 {
1733                         delete pEditBgEffectBitmap;
1734                         pEditBgEffectBitmap = null;
1735                 }
1736         }
1737         delete pReplacementColorBackgroundBitmap;
1738         pReplacementColorBackgroundBitmap = null;
1739
1740         return E_SUCCESS;
1741 CATCH:
1742         delete pEditBgBitmap;
1743
1744         return r;
1745 }
1746
1747 result
1748 _EditPresenter::DrawBackground(Canvas& canvas, bool drawTitleText)
1749 {
1750         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
1751         {
1752                 return DrawSingleLineBackground(canvas, drawTitleText);
1753         }
1754
1755         FloatRectangle editRect(0.0f, 0.0f, __pEdit->GetBoundsF().width, __pEdit->GetBoundsF().height);
1756
1757         EditStatus editStatus = GetCurrentStatus();
1758
1759         Bitmap* pEditBgBitmap = __pEdit->GetBackgroundBitmap(editStatus);
1760
1761         if (pEditBgBitmap)
1762         {
1763                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pEditBgBitmap))
1764                 {
1765                         canvas.DrawNinePatchedBitmap(editRect, *pEditBgBitmap);
1766                 }
1767                 else
1768                 {
1769                         canvas.DrawBitmap(editRect, *pEditBgBitmap);
1770                 }
1771         }
1772         else
1773         {
1774                 DrawBackgroundBitmap(canvas, IsCurrentFocused());
1775         }
1776
1777         DrawFocusRing(canvas);
1778
1779         if (drawTitleText)
1780         {
1781                 if ((__pEdit->GetEditStyle() & EDIT_STYLE_TITLE_TOP) || (__pEdit->GetEditStyle() & EDIT_STYLE_TITLE_LEFT))
1782                 {
1783                         DrawTitleText();
1784                 }
1785         }
1786
1787         return E_SUCCESS;
1788 }
1789
1790 result
1791 _EditPresenter::DrawTitleText()
1792 {
1793         result r = E_SUCCESS;
1794         if (__titleText == -1)
1795         {
1796                 return E_SYSTEM;
1797         }
1798
1799         Variant value;
1800         TextObjectActionType titleAction;
1801         Canvas* pTitleTextCanvas = null;
1802         _VisualElement* pRootElement = __pEdit->GetVisualElement();
1803         SysTryReturn(NID_UI_CTRL, pRootElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1804
1805         if (!__pTitleTextVisualElement)
1806         {
1807                 __pTitleTextVisualElement = new (std::nothrow) _VisualElement();
1808                 SysTryReturnResult(NID_UI_CTRL, __pTitleTextVisualElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
1809
1810                 r = __pTitleTextVisualElement->Construct();
1811                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct _VisualElement.");
1812
1813                 __pTitleTextVisualElement->SetImplicitAnimationEnabled(false);
1814                 __pTitleTextVisualElement->SetShowState(true);
1815
1816                 r = pRootElement->AttachChild(*__pTitleTextVisualElement);
1817                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1818         }
1819
1820         __pTitleTextVisualElement->SetBounds(__titleBounds);
1821
1822         pTitleTextCanvas = __pTitleTextVisualElement->GetCanvasN();
1823         SysTryCatch(NID_UI_CTRL, pTitleTextCanvas, , r, "[%s] Propagating.", GetErrorMessage(r));
1824
1825         pTitleTextCanvas->SetBackgroundColor(Color(0));
1826         pTitleTextCanvas->Clear();
1827
1828         titleAction = __pTitleTextObject->GetAction();
1829         if (IsCurrentFocused() == true)
1830         {
1831                 __pTitleTextObject->SetForegroundColor(__pEdit->GetTitleTextColor(EDIT_STATUS_HIGHLIGHTED), 0, __pTitleTextObject->GetTextLength());
1832
1833                 if (titleAction != __titleSlidingAction)
1834                 {
1835                         __pTitleTextObject->SetAction(__titleSlidingAction);
1836                         __pTitleTextObject->Compose();
1837                 }
1838
1839                 __pTitleTextObject->SetBounds(FloatRectangle(0.0f, 0.0f, __titleBounds.width, __titleBounds.height));
1840                 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pTitleTextCanvas));
1841
1842                 StopTitleSlidingTimer();
1843                 if (__pTitleTextObject->IsActionOn() == true)
1844                 {
1845                         StartTitleSlidingTimer();
1846                 }
1847         }
1848         else
1849         {
1850                 __pTitleTextObject->SetForegroundColor(__pEdit->GetTitleTextColor(GetCurrentStatus()), 0, __pTitleTextObject->GetTextLength());
1851
1852                 if (titleAction != TEXT_OBJECT_ACTION_TYPE_ABBREV)
1853                 {
1854                         __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1855                 }
1856                 // Draw title text
1857                 __pTitleTextObject->SetBounds(FloatRectangle(0.0f, 0.0f, __titleBounds.width, __titleBounds.height));
1858                 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(*pTitleTextCanvas));
1859         }
1860
1861         delete pTitleTextCanvas;
1862
1863         return E_SUCCESS;
1864
1865 CATCH:
1866         __pTitleTextVisualElement->Destroy();
1867         __pTitleTextVisualElement = null;
1868
1869         return r;
1870 }
1871
1872 void
1873 _EditPresenter::DrawText(void)
1874 {
1875         Canvas* pCanvas = null;
1876
1877         // In case of unfocused and touch moving
1878         if (__isTouchMoving && !__pTextVisualElement)
1879         {
1880                 result r = E_SUCCESS;
1881                 __pTextVisualElement = new (std::nothrow) _VisualElement;
1882                 SysTryReturnVoidResult(NID_UI_CTRL, __pTextVisualElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1883
1884                 r = __pTextVisualElement->Construct();
1885                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
1886
1887                 __pTextVisualElement->SetSurfaceOpaque(false);
1888                 __pTextVisualElement->SetImplicitAnimationEnabled(false);
1889
1890                 __pTextVisualElement->SetShowState(true);
1891
1892                 _VisualElement* pEditVisualElement = __pEdit->GetVisualElement();
1893                 SysTryCatch(NID_UI_CTRL, pEditVisualElement, , r = E_SYSTEM, "[E_SYSTEM] Unable to get root visual element.");
1894
1895                 pEditVisualElement->AttachChild(*__pTextVisualElement);
1896                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add child", GetErrorMessage(r));
1897
1898                 pCanvas = __pEdit->GetCanvasN();
1899                 SysTryCatch(NID_UI_CTRL, pCanvas, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1900
1901                 pCanvas->SetBackgroundColor(Color(0));
1902                 r = pCanvas->Clear();
1903                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1904
1905                 DrawBackground(*pCanvas);
1906
1907                 delete pCanvas;
1908                 pCanvas = null;
1909         }
1910
1911         if (__pTextVisualElement)
1912         {
1913                 FloatRectangle editBounds = __pEdit->GetBoundsF();
1914                 __pTextVisualElement->SetOpacity(1.0f);
1915                 __pTextVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, editBounds.width, editBounds.height));
1916                 pCanvas = __pTextVisualElement->GetCanvasN();
1917                 if (pCanvas == null)
1918                 {
1919                         return;
1920                 }
1921                 pCanvas->SetBackgroundColor(Color(0));
1922                 pCanvas->Clear();
1923
1924                 if (__pEdit->GetEditStyle() & EDIT_STYLE_CLEAR)
1925                 {
1926                         if (GetSearchBarFlag()) //SearchBar
1927                         {
1928                                 if (__pTextString->GetLength() == 0)
1929                                 {
1930                                         if (__isClearIconVisible)
1931                                         {
1932                                                 __isClearIconVisible = false;
1933                                                 AdjustTextBounds(__isClearIconVisible);
1934                                         }
1935                                 }
1936                                 else
1937                                 {
1938                                         if (!__isClearIconVisible)
1939                                         {
1940                                                 __isClearIconVisible = true;
1941                                                 AdjustTextBounds(__isClearIconVisible);
1942                                         }
1943
1944                                         DrawClearIcon(*pCanvas);
1945                                 }
1946                         }
1947                         else //EditField
1948                         {
1949                                 if (IsCurrentFocused() == true)
1950                                 {
1951                                         if (__pTextString->GetLength() == 0)
1952                                         {
1953                                                 if (__isClearIconVisible)
1954                                                 {
1955                                                         __isClearIconVisible = false;
1956                                                         AdjustTextBounds(__isClearIconVisible);
1957                                                 }
1958                                         }
1959                                         else
1960                                         {
1961                                                 if (!__isClearIconVisible)
1962                                                 {
1963                                                         __isClearIconVisible = true;
1964                                                         AdjustTextBounds(__isClearIconVisible);
1965                                                 }
1966
1967                                                 DrawClearIcon(*pCanvas);
1968                                         }
1969                                 }
1970                                 else
1971                                 {
1972                                         if (__isClearIconVisible)
1973                                         {
1974                                                 __isClearIconVisible = false;
1975                                                 AdjustTextBounds(__isClearIconVisible);
1976                                         }
1977                                 }
1978                         }
1979                 }
1980
1981                 DrawText(*pCanvas);
1982                 InitializeCursor();
1983                 delete pCanvas;
1984         }
1985
1986         return;
1987
1988 CATCH:
1989         __pTextVisualElement->Destroy();
1990         __pTextVisualElement = null;
1991
1992         if (pCanvas)
1993         {
1994                 delete pCanvas;
1995                 pCanvas = null;
1996         }
1997
1998         return;
1999 }
2000
2001 result
2002 _EditPresenter::DrawText(Canvas& canvas)
2003 {
2004         result r = E_SUCCESS;
2005
2006         if (__pEdit->GetEnableState() == false)
2007         {
2008                 __pTextObject->SetAlternateLookEnabled(true);
2009                 Color tempColor = __pEdit->GetTextColor(EDIT_STATUS_DISABLED);
2010                 __pTextObject->SetAlternativeForegroundColor(tempColor);
2011         }
2012         else
2013         {
2014                 __pTextObject->SetAlternateLookEnabled(false);
2015         }
2016
2017
2018         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
2019         {
2020                 return DrawTextForEntireFontSetting(canvas);
2021         }
2022
2023         // initital guide text
2024         if (IsGuideTextActivated())
2025         {
2026                 __pGuideTextObject->SetForegroundColor(__pEdit->GetGuideTextColor(), 0, __pGuideTextObject->GetTextLength());
2027
2028                 if (__isGuideTextColorChanged == true && __pEdit->IsSettingGuideTextColor() == false)
2029                 {
2030                         __pGuideTextObject->SetForegroundColor(__pEdit->GetTextColor(EDIT_STATUS_NORMAL), 0, __pGuideTextObject->GetTextLength());
2031                         __pGuideTextObject->SetBounds(__textObjectBounds);
2032                         __pGuideTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
2033                         __pGuideTextObject->SetForegroundColor(__pEdit->GetTextColor(EDIT_STATUS_DISABLED), 0, __pGuideTextObject->GetTextLength());
2034                         __isGuideTextColorChanged = false;
2035                 }
2036                 else
2037                 {
2038                         __pGuideTextObject->SetBounds(__textObjectBounds);
2039                         __pGuideTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
2040                 }
2041         }
2042
2043         if (GetTextLength() <= 0)
2044         {
2045                 return E_SUCCESS;
2046         }
2047         ConvertLinkType();
2048
2049         EditStatus editStatus = GetCurrentStatus();
2050
2051         __pTextObject->SetForegroundColor(__pEdit->GetTextColor(editStatus), 0, __pTextObject->GetTextLength());
2052         if (__isTextBlocked)
2053         {
2054                 __pTextObject->SetForegroundColor(__blockTextColor, __blockStartPos, __cursorPos - __blockStartPos);
2055         }
2056
2057         if (__isTextBlocked == true && editStatus == EDIT_STATUS_HIGHLIGHTED)
2058         {
2059                 __pTextObject->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_HIGHLIGHTED), 0, __pTextObject->GetTextLength());
2060                 __pTextObject->SetBlock(true);
2061                 __pTextObject->SetBlockRange(__blockStartPos, __cursorPos - __blockStartPos);
2062         }
2063         else if (__isTextBlocked == true && editStatus == EDIT_STATUS_PRESSED)
2064         {
2065                 __pTextObject->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_PRESSED), 0, __pTextObject->GetTextLength());
2066                 __pTextObject->SetBlock(true);
2067                 __pTextObject->SetBlockRange(__blockStartPos, __cursorPos - __blockStartPos);
2068         }
2069         else if (__isTextBlocked == true && editStatus == EDIT_STATUS_NORMAL)
2070         {
2071                 __pTextObject->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_NORMAL), 0, __pTextObject->GetTextLength());
2072                 __pTextObject->SetBlock(true);
2073                 __pTextObject->SetBlockRange(__blockStartPos, __cursorPos - __blockStartPos);
2074         }
2075         else
2076         {
2077                 __pTextObject->SetBlock(false);
2078                 __isTextBlocked = false;
2079         }
2080
2081         UpdateComponentInformation();
2082
2083         __pTextObject->SetBounds(__textObjectBounds);
2084         __pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
2085
2086         if (__isTextBlocked == true && editStatus == EDIT_STATUS_HIGHLIGHTED)
2087         {
2088                 __pTextObject->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK),  0, __pTextObject->GetTextLength());
2089         }
2090
2091         DrawTextBlockLine(canvas);
2092
2093         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
2094
2095         return r;
2096 }
2097
2098 void
2099 _EditPresenter::DrawTextBlockLine(Canvas& canvas)
2100 {
2101         if (!__isTextBlocked)
2102         {
2103                 return;
2104         }
2105         int leftHandlerCursorPos = 0;
2106         int rightHandlerCursorPos = 0;
2107         int leftRowIndex = -1;
2108         int leftColumnIndex = -1;
2109         int rightRowIndex = -1;
2110         int rightColumnIndex = -1;
2111
2112         Color textBlockLineColor;
2113         GET_COLOR_CONFIG(EDIT::CURSOR_NORMAL, textBlockLineColor);
2114
2115         FloatRectangle cursorBounds;
2116         FloatRectangle textObjectBounds = __textObjectBounds;
2117         textObjectBounds.x -= 1;
2118         textObjectBounds.width = textObjectBounds.width + 2;
2119
2120         if (__pCopyPasteManager)
2121         {
2122                 __pCopyPasteManager->GetHandlerRowColumnIndex(false, true, leftRowIndex, leftColumnIndex);
2123                 __pCopyPasteManager->GetHandlerRowColumnIndex(false, false, rightRowIndex, rightColumnIndex);
2124                 leftHandlerCursorPos = __pCopyPasteManager->GetHandlerCursorPosition(_EditCopyPasteManager::HANDLER_TYPE_LEFT);
2125                 rightHandlerCursorPos = __pCopyPasteManager->GetHandlerCursorPosition(_EditCopyPasteManager::HANDLER_TYPE_RIGHT);
2126
2127                 if (leftRowIndex != -1 && leftColumnIndex != -1)
2128                 {
2129                         CalculateCursorBounds(__textObjectBounds, cursorBounds, leftRowIndex, leftColumnIndex);
2130                 }
2131                 else
2132                 {
2133                         CalculateCursorBounds(__textObjectBounds, cursorBounds, leftHandlerCursorPos);
2134                 }
2135                 if (cursorBounds.x != -1)
2136                 {
2137                         cursorBounds.x -= 1;
2138                         cursorBounds = cursorBounds.GetIntersection(textObjectBounds);
2139                         canvas.FillRectangle(textBlockLineColor, cursorBounds);
2140                 }
2141                 if (rightRowIndex != -1 && rightColumnIndex != -1)
2142                 {
2143                         CalculateCursorBounds(__textObjectBounds, cursorBounds, rightRowIndex, rightColumnIndex);
2144                 }
2145                 else
2146                 {
2147                         CalculateCursorBounds(__textObjectBounds, cursorBounds, rightHandlerCursorPos);
2148                 }
2149                 if (cursorBounds.x != -1 && cursorBounds.x <= __textObjectBounds.x + __textObjectBounds.width)
2150                 {
2151                         cursorBounds.x -= 1;
2152                         cursorBounds = cursorBounds.GetIntersection(textObjectBounds);
2153                         canvas.FillRectangle(textBlockLineColor, cursorBounds);
2154                 }
2155         }
2156 }
2157
2158 result
2159 _EditPresenter::DrawTextForEntireFontSetting(Canvas& canvas)
2160 {
2161         result r = E_SUCCESS;
2162
2163         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD) && IsCurrentFocused() == false)
2164         {
2165                 __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2166         }
2167         else
2168         {
2169                 if (__pTextObject->GetAction() != TEXT_OBJECT_ACTION_TYPE_NONE)
2170                 {
2171                         __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
2172                         __isCursorChanged = true;
2173                 }
2174         }
2175
2176         // initital guide text
2177         if (IsGuideTextActivated())
2178         {
2179                 __pGuideTextObject->SetForegroundColor(__pEdit->GetGuideTextColor(), 0, __pGuideTextObject->GetTextLength());
2180
2181                 if (__isGuideTextColorChanged == true && __pEdit->IsSettingGuideTextColor() == false)
2182                 {
2183                         __pGuideTextObject->SetForegroundColor(__pEdit->GetTextColor(EDIT_STATUS_NORMAL), 0, __pGuideTextObject->GetTextLength());
2184                         __pGuideTextObject->SetBounds(__textObjectBounds);
2185                         __pGuideTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
2186                         __pGuideTextObject->SetForegroundColor(__pEdit->GetTextColor(EDIT_STATUS_DISABLED), 0, __pGuideTextObject->GetTextLength());
2187                         __isGuideTextColorChanged = false;
2188                 }
2189                 else
2190                 {
2191                         __pGuideTextObject->SetBounds(__textObjectBounds);
2192                         __pGuideTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
2193                 }
2194         }
2195
2196         if (GetTextLength() <= 0)
2197         {
2198                 return E_SUCCESS;
2199         }
2200         ConvertLinkType();
2201
2202         EditStatus editStatus = GetCurrentStatus();
2203
2204         if (IsCurrentFocused() == false)
2205         {
2206                 if (__isCursorChanged == true)
2207                 {
2208                         if (AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT) == true)
2209                         {
2210                                 __pTextObject->Compose();
2211                         }
2212                 }
2213                 if (!(__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD))
2214                 {
2215                         __pTextObject->SetFirstDisplayLineIndexFromTextIndex(0);
2216                 }
2217                 __pTextObject->SetForegroundColor(__pEdit->GetTextColor(editStatus), 0, __pTextObject->GetTextLength());
2218                 __pTextObject->SetBlock(false);
2219         }
2220         else
2221         {
2222                 int startRange = 0;
2223                 int lengthRange = 0;
2224
2225                 __pTextObject->GetRange(startRange, lengthRange);
2226                 __pTextObject->SetRange(0, GetTextLength());
2227                 __pTextObject->SetForegroundColor(__pEdit->GetTextColor(editStatus), 0, __pTextObject->GetTextLength());
2228                 if (__isTextBlocked)
2229                 {
2230                         __pTextObject->SetForegroundColor(__blockTextColor, __blockStartPos, __cursorPos - __blockStartPos);
2231                 }
2232
2233                 if (IsBlocked() == true && editStatus == EDIT_STATUS_HIGHLIGHTED)
2234                 {
2235                         __pTextObject->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_HIGHLIGHTED), 0, __pTextObject->GetTextLength());
2236                         __pTextObject->SetBlock(true);
2237                         __pTextObject->SetRange(__blockStartPos, __cursorPos - __blockStartPos);
2238                 }
2239                 else if (__isTextBlocked == true && editStatus == EDIT_STATUS_PRESSED)
2240                 {
2241                         __pTextObject->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_PRESSED), 0, __pTextObject->GetTextLength());
2242                         __pTextObject->SetBlock(true);
2243                         __pTextObject->SetBlockRange(__blockStartPos, __cursorPos - __blockStartPos);
2244                 }
2245                 else if (__isTextBlocked == true && editStatus == EDIT_STATUS_NORMAL)
2246                 {
2247                         __pTextObject->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_NORMAL), 0, __pTextObject->GetTextLength());
2248                         __pTextObject->SetBlock(true);
2249                         __pTextObject->SetBlockRange(__blockStartPos, __cursorPos - __blockStartPos);
2250                 }
2251                 else
2252                 {
2253                         __pTextObject->SetBlock(false);
2254                         __isTextBlocked = false;
2255                 }
2256
2257                 UpdateComponentInformation();
2258         }
2259
2260         __pTextObject->SetBounds(__textObjectBounds);
2261         __pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
2262
2263         DrawTextBlockLine(canvas);
2264
2265         return r;
2266 }
2267
2268 result
2269 _EditPresenter::DrawSingleLineBackground(Canvas& canvas, bool drawTitleText)
2270 {
2271         FloatRectangle editField(0.0f, 0.0f, __pEdit->GetBoundsF().width, __pEdit->GetBoundsF().height);
2272         EditStatus editStatus = GetCurrentStatus();
2273
2274         Bitmap* pEditBgBitmap = __pEdit->GetBackgroundBitmap(editStatus);
2275
2276         if (pEditBgBitmap)
2277         {
2278                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pEditBgBitmap))
2279                 {
2280                         canvas.DrawNinePatchedBitmap(editField, *pEditBgBitmap);
2281                 }
2282                 else
2283                 {
2284                         canvas.DrawBitmap(editField, *pEditBgBitmap);
2285                 }
2286         }
2287         else
2288         {
2289                 DrawSingleLineBackgroundBitmap(canvas, IsCurrentFocused());
2290         }
2291
2292         DrawFocusRing(canvas);
2293
2294         if (drawTitleText)
2295         {
2296                 if (((__pEdit->GetEditStyle() & EDIT_STYLE_TITLE_LEFT) && !(__titleText.GetLength() == 0)) || (__pEdit->GetEditStyle() & EDIT_STYLE_TITLE_TOP))
2297                 {
2298                         DrawTitleText();
2299                 }
2300         }
2301
2302         return E_SUCCESS;
2303 }
2304
2305
2306 result
2307 _EditPresenter::DrawSingleLineBackgroundBitmap(Canvas& canvas, bool focused)
2308 {
2309         if (__isTouchPressed)
2310         {
2311                 DrawChangeableBackground(canvas, focused, 0, 0);
2312         }
2313         else
2314         {
2315                 if (focused)
2316                 {
2317                         DrawChangeableBackground(canvas, focused, 0, 0, true, 0);
2318                 }
2319                 else
2320                 {
2321                         bool tmpFocused = focused;
2322                         DrawChangeableBackground(canvas, tmpFocused, 0, 0);
2323                 }
2324         }
2325
2326         return true;
2327 }
2328
2329 result
2330 _EditPresenter::DrawClearIcon(Canvas& canvas)
2331 {
2332         result r = E_SUCCESS;
2333
2334         float clearIconWidth = 0.0f;
2335         float clearIconHeight = 0.0f;
2336         float cursorWidth = 0.0f;
2337
2338         _ControlOrientation orientation = __pEdit->GetOrientation();
2339         GET_SHAPE_CONFIG(EDIT::CLEAR_ICON_WIDTH, orientation, clearIconWidth);
2340         GET_SHAPE_CONFIG(EDIT::CLEAR_ICON_HEIGHT, orientation, clearIconHeight);
2341         GET_SHAPE_CONFIG(EDIT::CURSOR_WIDTH, __pEdit->GetOrientation(), cursorWidth);
2342
2343         if (__pTextString->GetLength() == 0)
2344         {
2345                 return E_SUCCESS;
2346         }
2347
2348         Bitmap* pEditBitmapClear = null;
2349         Color editClearIconColor;
2350
2351         if (!__pEdit->IsEnabled())
2352         {
2353                 GET_COLOR_CONFIG(EDIT::CLEAR_ICON_DISABLED, editClearIconColor);
2354                 r = GET_REPLACED_BITMAP_CONFIG_N(EDIT::CLEAR_ICON_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, editClearIconColor, pEditBitmapClear);
2355
2356                 if (pEditBitmapClear == null)
2357                 {
2358                         return E_SYSTEM;
2359                 }
2360         }
2361         else if (__isClearIconPressed)
2362         {
2363                 GET_COLOR_CONFIG(EDIT::CLEAR_ICON_PRESSED, editClearIconColor);
2364                 r = GET_REPLACED_BITMAP_CONFIG_N(EDIT::CLEAR_ICON_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, editClearIconColor, pEditBitmapClear);
2365
2366                 if (pEditBitmapClear == null)
2367                 {
2368                         return E_SYSTEM;
2369                 }
2370         }
2371         else
2372         {
2373                 GET_COLOR_CONFIG(EDIT::CLEAR_ICON_NORMAL, editClearIconColor);
2374                 r = GET_REPLACED_BITMAP_CONFIG_N(EDIT::CLEAR_ICON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, editClearIconColor, pEditBitmapClear);
2375                 if (pEditBitmapClear == null)
2376                 {
2377                         return E_SYSTEM;
2378                 }
2379         }
2380
2381         FloatRectangle textRect = __textObjectBounds;
2382         FloatRectangle afterClearIconRect(textRect.x + textRect.width + cursorWidth, textRect.y + (textRect.height - clearIconHeight) / 2.0f, clearIconWidth, clearIconHeight);
2383         FloatRectangle editBounds = __pEdit->GetBoundsF();
2384
2385         if (__clearIconBounds != afterClearIconRect)
2386         {
2387                 __clearIconBounds = afterClearIconRect;
2388                 __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_CLEAR_ICON);
2389         }
2390
2391         if (editBounds.height < clearIconHeight)
2392         {
2393                 __clearIconBounds.y = textRect.y;
2394         }
2395
2396         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pEditBitmapClear))
2397         {
2398                 r = canvas.DrawNinePatchedBitmap(__clearIconBounds, *pEditBitmapClear);
2399         }
2400         else
2401         {
2402                 r = canvas.DrawBitmap(__clearIconBounds, *pEditBitmapClear);
2403         }
2404
2405         if (pEditBitmapClear)
2406         {
2407                 delete pEditBitmapClear;
2408                 pEditBitmapClear = null;
2409         }
2410
2411         return r;
2412 }
2413
2414 result
2415 _EditPresenter::Draw(void)
2416 {
2417         result r = E_SUCCESS;
2418
2419         if (__isInitialized == false)
2420         {
2421                 r = InitializeAtFirstDrawing();
2422                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Faild to initialize.");
2423
2424                 if (IsCurrentFocused() == true &&  __isInputConnectionBound == false)
2425                 {
2426                         if (IsViewModeEnabled() == false)
2427                         {
2428                                 if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
2429                                 {
2430                                         ShowKeypad(false);
2431                                 }
2432                                 else
2433                                 {
2434                                         ShowFullscreenKeypad();
2435                                 }
2436                         }
2437                 }
2438         }
2439
2440         //Do not change the bounds of the edit control after acquiring a canvas.
2441         Canvas* pCanvas = __pEdit->GetCanvasN();
2442         SysTryReturnResult(NID_UI_CTRL, pCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
2443
2444         __isCursorOpaque = true;
2445
2446         pCanvas->SetBackgroundColor(Color(0));
2447         r = pCanvas->Clear();
2448         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2449
2450         DrawBackground(*pCanvas);
2451
2452         if (__pTextVisualElement)
2453         {
2454                 DrawText();
2455         }
2456         else
2457         {
2458
2459                 if (__pEdit->GetEditStyle() & EDIT_STYLE_CLEAR)
2460                 {
2461                         if (GetSearchBarFlag()) //SearchBar
2462                         {
2463                                 if (__pTextString->GetLength() == 0)
2464                                 {
2465                                         if (__isClearIconVisible)
2466                                         {
2467                                                 __isClearIconVisible = false;
2468                                                 AdjustTextBounds(__isClearIconVisible);
2469                                         }
2470                                 }
2471                                 else
2472                                 {
2473                                         if (!__isClearIconVisible)
2474                                         {
2475                                                 __isClearIconVisible = true;
2476                                                 AdjustTextBounds(__isClearIconVisible);
2477                                         }
2478
2479                                         DrawClearIcon(*pCanvas);
2480                                 }
2481                         }
2482                         else //EditField
2483                         {
2484                                 if (IsCurrentFocused() == true)
2485                                 {
2486                                         if (__pTextString->GetLength() == 0)
2487                                         {
2488                                                 if (__isClearIconVisible)
2489                                                 {
2490                                                         __isClearIconVisible = false;
2491                                                         AdjustTextBounds(__isClearIconVisible);
2492                                                 }
2493                                         }
2494                                         else
2495                                         {
2496                                                 if (!__isClearIconVisible)
2497                                                 {
2498                                                         __isClearIconVisible = true;
2499                                                         AdjustTextBounds(__isClearIconVisible);
2500                                                 }
2501
2502                                                 DrawClearIcon(*pCanvas);
2503                                         }
2504                                 }
2505                                 else
2506                                 {
2507                                         if(__isClearIconVisible)
2508                                         {
2509                                                 __isClearIconVisible = false;
2510                                                 AdjustTextBounds(__isClearIconVisible);
2511                                         }
2512                                 }
2513                         }
2514                 }
2515
2516                 DrawText(*pCanvas);
2517         }
2518
2519         RestoreCopyPasteManager();
2520
2521         if (__isCopyPasteManagerExist)
2522         {
2523                 __pCopyPasteManager->Show();
2524         }
2525
2526         InitializeCursor();
2527
2528         // Set scroll bar
2529         DrawScrollBar();
2530
2531         //To avoid resizing to Flexible bounds on User SetBounds in Non-focussed mode
2532         if (IsFocused() || (!__isAutoShrinkEnabled))
2533         {
2534                 if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
2535                 {
2536                         AdjustFlexibleHeight();
2537                 }
2538         }
2539
2540         delete pCanvas;
2541
2542         return r;
2543
2544 CATCH:
2545         delete pCanvas;
2546
2547         return r;
2548 }
2549
2550 void
2551 _EditPresenter::RestoreCopyPasteManager(void)
2552 {
2553         if (__rotated && !__clipboardConnected) // Command button should be relocated after rotation in case of no keypad.
2554         {
2555                 if (__isCopyPasteManagerExist)
2556                 {
2557                         PostInternalEvent(String(L"ShowCopyPaste"));
2558                 }
2559                 __rotated = false;
2560         }
2561 }
2562
2563 result
2564 _EditPresenter::ConvertLinkType(void)
2565 {
2566         if (__isCutLinkParserEnabled == false || IsViewModeEnabled() == false)
2567         {
2568                 return E_SUCCESS;
2569         }
2570
2571         unsigned long autoLinkMask = GetAutoLinkMask();
2572         bool isChangingCutLink = false;
2573         EditCutLinkType editLinkType = EDIT_LINK_TYPE_INVALID;
2574         TextCutLinkParser cutlinkParser;
2575         cutlinkParser.SetCutLinkMask(autoLinkMask);
2576         TextLinkInfo* pLinkInfo = cutlinkParser.Parse(__pTextBuffer, wcslen(__pTextBuffer), 0);
2577         TextLinkInfo* pNextLinkInfo = null;
2578         int cursorPos = __cursorPos;
2579
2580         __isCutLinkParserEnabled = false;
2581
2582         while (pLinkInfo != null)
2583         {
2584                 if (IsViewModeEnabled() == true)
2585                 {
2586                         switch (pLinkInfo->linkType)
2587                         {
2588                         case LINK_TYPE_URL:
2589                                 if (autoLinkMask & LINK_TYPE_URL)
2590                                 {
2591                                         isChangingCutLink = true;
2592                                         editLinkType = EDIT_LINK_TYPE_URL;
2593                                 }
2594                                 break;
2595
2596                         case LINK_TYPE_EMAIL:
2597                                 if (autoLinkMask & LINK_TYPE_EMAIL)
2598                                 {
2599                                         isChangingCutLink = true;
2600                                         editLinkType = EDIT_LINK_TYPE_URL;
2601                                 }
2602                                 break;
2603
2604                         case LINK_TYPE_TEL_NUM:
2605                                 if (autoLinkMask & LINK_TYPE_TEL_NUM)
2606                                 {
2607                                         isChangingCutLink = true;
2608                                         editLinkType = EDIT_LINK_TYPE_PHONE_NUM;
2609                                 }
2610                                 break;
2611
2612                         default:
2613                                 editLinkType = EDIT_LINK_TYPE_INVALID;
2614                                 break;
2615                         }
2616                 }
2617                 else
2618                 {
2619                         _Text::TextElement* pTextElement = __pTextObject->GetElementAtTextIndex(pLinkInfo->srcOffset);
2620                         if (pTextElement != null && pTextElement->GetType() != TEXT_ELEMENT_TYPE_CUTLINK)
2621                         {
2622                                 pNextLinkInfo = pLinkInfo->pNextLinkInfo;
2623                                 delete pLinkInfo;
2624                                 pLinkInfo = pNextLinkInfo;
2625                                 continue;
2626                         }
2627                 }
2628
2629                 wchar_t* pCutLinkString = null;
2630                 result r = E_SUCCESS;
2631
2632                 pCutLinkString = new(std::nothrow) wchar_t[(pLinkInfo->length + 1) * sizeof(wchar_t)];
2633
2634                 if (!pCutLinkString)
2635                 {
2636                         while (pLinkInfo != null)
2637                         {
2638                                 pNextLinkInfo = pLinkInfo->pNextLinkInfo;
2639                                 delete pLinkInfo;
2640                                 pLinkInfo = pNextLinkInfo;
2641                         }
2642                         SysLog(NID_UI_CTRL, "[E_SYSTEM] Unable to allocate cutlink text buffer.");
2643                         return E_SYSTEM;
2644                 }
2645
2646                 for (int i = 0; i < pLinkInfo->length; i++)
2647                 {
2648                         pCutLinkString[i] = __pTextBuffer[pLinkInfo->srcOffset + i];
2649                 }
2650                 pCutLinkString[pLinkInfo->length] = null;
2651
2652                 r = DeleteText(pLinkInfo->srcOffset, pLinkInfo->srcOffset + pLinkInfo->length);
2653
2654                 if (r == E_SUCCESS)
2655                 {
2656                         int currentLength = __pTextString->GetLength();
2657                         int fullLength = currentLength + pLinkInfo->length;
2658
2659                         r = __pTextString->Insert(String(pCutLinkString), pLinkInfo->srcOffset);
2660                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2661
2662                         wchar_t pOriginalString[currentLength - pLinkInfo->srcOffset];
2663
2664                         // Save original text.
2665                         for (int i = 0; i < currentLength - pLinkInfo->srcOffset; i++)
2666                         {
2667                                 pOriginalString[i] = __pTextBuffer[pLinkInfo->srcOffset + i];
2668                         }
2669                         pOriginalString[currentLength - pLinkInfo->srcOffset] = 0;
2670
2671                         // Insert text.
2672                         for (int i = 0; i < pLinkInfo->length; i++)
2673                         {
2674                                 __pTextBuffer[i + pLinkInfo->srcOffset] = pCutLinkString[i];
2675                         }
2676
2677                         // Append origianal text.
2678                         for (int i = 0; i < currentLength - pLinkInfo->srcOffset; i++)
2679                         {
2680                                 __pTextBuffer[i + pLinkInfo->srcOffset + pLinkInfo->length] = pOriginalString[i];
2681                         }
2682                         __pTextBuffer[fullLength] = 0;
2683                 }
2684
2685                 if (isChangingCutLink)
2686                 {
2687                         TextCutLink* pCutLinkObject = null;
2688                         EditCutlinkColor cutlinkColor;
2689
2690                         Font* pFont = _FontImpl::CloneN(const_cast <Font&>(*__pFont));
2691                         SysTryReturnResult(NID_UI_CTRL, pFont, GetLastResult(), "Unable to get font.");
2692
2693                         _FontImpl* fontImpl = _FontImpl::GetInstance(*pFont);
2694                         SysTryReturnResult(NID_UI_CTRL, fontImpl, GetLastResult(), "fontImpl is null.");
2695                         fontImpl->SetUnderline(true);
2696
2697                         __pEdit->GetCutlinkColorInfo(editLinkType, &cutlinkColor);
2698                         pCutLinkObject = new (std::nothrow) TextCutLink(false, pLinkInfo->linkType, pCutLinkString, pLinkInfo->length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL, pFont,
2699                                                                                                                          cutlinkColor.cutlinkFgColor, cutlinkColor.cutlinkBgColor, 0);
2700
2701                         delete pFont;
2702
2703                         if (pCutLinkObject == null)
2704                         {
2705                                 SysLog(NID_UI_CTRL, "Unable to allocate cutlink object.");
2706                         }
2707                         else
2708                         {
2709                                 pCutLinkObject->SetEditModeEnable(true);
2710                                 __pTextObject->InsertElementAt(pLinkInfo->srcOffset, *pCutLinkObject);
2711                                 __pTextObject->ChangeTextOffset(__pTextBuffer, pLinkInfo->srcOffset, pLinkInfo->length);
2712                         }
2713                 }
2714                 else
2715                 {
2716                         TextSimple* pSimpleText = null;
2717                         pSimpleText = new (std::nothrow) TextSimple(pCutLinkString, pLinkInfo->length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL, GetFont());
2718
2719                         if (pSimpleText == null)
2720                         {
2721                                 SysLog(NID_UI_CTRL, "Unable to allocate text object.");
2722
2723                         }
2724                         else
2725                         {
2726                                 __pTextObject->InsertElementAt(pLinkInfo->srcOffset, *pSimpleText);
2727                                 __pTextObject->ChangeTextOffset(__pTextBuffer, pLinkInfo->srcOffset, pSimpleText->GetTextLength());
2728                         }
2729                 }
2730
2731                 pNextLinkInfo = pLinkInfo->pNextLinkInfo;
2732                 delete pLinkInfo;
2733                 pLinkInfo = pNextLinkInfo;
2734
2735                 if (pCutLinkString != null)
2736                 {
2737                         delete[] pCutLinkString;
2738                         pCutLinkString = null;
2739                 }
2740         }
2741
2742         __pTextObject->Compose();
2743
2744         bool isCursorChanged = __isCursorChanged;
2745         SetCursorPosition(cursorPos);
2746         __isCursorChanged = isCursorChanged;
2747
2748         return E_SUCCESS;
2749 }
2750
2751 int
2752 _EditPresenter::GetLinkElementOffsetInTextBuffer(int elementIndex) const
2753 {
2754         const int textElementCount = __pTextObject->GetElementCount();
2755         SysTryReturn(NID_UI_CTRL, elementIndex >= 0 && elementIndex <= textElementCount, -1, E_OUT_OF_RANGE, "The Invalid argument is given.");
2756
2757         _Text::TextElement* pTextElement = null;
2758         int elementOffset = -1;
2759         int elementLength = 0;
2760         int prevOffset = 0;
2761         int prevLength = 0;
2762
2763         for (int index = 0; index <= elementIndex; index++)
2764         {
2765                 pTextElement = __pTextObject->GetElementAtElementIndex(index);
2766                 if (pTextElement == null)
2767                 {
2768                         return -1;
2769                 }
2770
2771                 elementOffset = static_cast<int>(pTextElement->GetValue(SET_TEXT_OFFSET));
2772                 elementLength = pTextElement->GetTextLength();
2773
2774                 if (pTextElement->GetType() == TEXT_ELEMENT_TYPE_CUTLINK)
2775                 {
2776                         elementOffset = prevOffset + prevLength;
2777                 }
2778
2779                 prevOffset = elementOffset;
2780                 prevLength = elementLength;
2781                 pTextElement = null;
2782         }
2783
2784         return elementOffset;
2785 }
2786
2787 bool
2788 _EditPresenter::IsTextBlockedInTokenEdit(void) const
2789 {
2790         return false;
2791 }
2792
2793 int
2794 _EditPresenter::GetCursorPositionAt(const FloatPoint& touchPoint) const
2795 {
2796         FloatPoint cursorPoint;
2797         int cursorPos = -1;
2798
2799         FloatRectangle textObjectBounds = __textObjectBounds;
2800
2801         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
2802         {
2803                 if (IsTextBlockedInTokenEdit())
2804                 {
2805                         textObjectBounds = GetTextBoundsF();
2806                 }
2807         }
2808
2809         if (textObjectBounds.Contains(touchPoint))
2810         {
2811                 cursorPoint.x = touchPoint.x - textObjectBounds.x;
2812                 cursorPoint.y = touchPoint.y - textObjectBounds.y;
2813         }
2814         else if (__textBoxBounds.Contains(touchPoint))
2815         {
2816                 if (touchPoint.y <= textObjectBounds.y)
2817                 {
2818                         cursorPoint.y = textObjectBounds.y + 1.0f;
2819                 }
2820                 else if (touchPoint.y >= (textObjectBounds.y + textObjectBounds.height))
2821                 {
2822                         cursorPoint.y = textObjectBounds.y + textObjectBounds.height - 1.0f;
2823                 }
2824                 else
2825                 {
2826                         cursorPoint.y = touchPoint.y;
2827                 }
2828
2829                 if (touchPoint.x <= textObjectBounds.x)
2830                 {
2831                         cursorPoint.x = textObjectBounds.x + 1.0f;
2832                 }
2833                 else if (touchPoint.x >= (textObjectBounds.x + textObjectBounds.width))
2834                 {
2835                         cursorPoint.x = textObjectBounds.x + textObjectBounds.width - 1.0f;
2836                 }
2837                 else
2838                 {
2839                         cursorPoint.x = touchPoint.x;
2840                 }
2841                 cursorPoint.y -= textObjectBounds.y;
2842                 cursorPoint.x -= textObjectBounds.x;
2843         }
2844         else
2845         {
2846                 return cursorPos;
2847         }
2848
2849         cursorPos = __pTextObject->GetTextIndexFromPosition(cursorPoint.x, cursorPoint.y);
2850
2851         return cursorPos;
2852 }
2853 int
2854 _EditPresenter::GetCursorPositionAt(const FloatPoint& touchPoint, int& rowIndex, int& columnIndex, bool isMoving)
2855 {
2856         FloatPoint cursorPoint;
2857         int cursorPos = -1;
2858
2859         FloatRectangle textObjectBounds = __textObjectBounds;
2860
2861         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
2862         {
2863                 if (IsTextBlockedInTokenEdit())
2864                 {
2865                         textObjectBounds = GetTextBoundsF();
2866                 }
2867         }
2868
2869         if (textObjectBounds.Contains(touchPoint))
2870         {
2871                 cursorPoint.x = touchPoint.x - textObjectBounds.x;
2872                 cursorPoint.y = touchPoint.y - textObjectBounds.y;
2873         }
2874         else if (__textBoxBounds.Contains(touchPoint) && !isMoving)
2875         {
2876                 if (touchPoint.y <= textObjectBounds.y)
2877                 {
2878                         cursorPoint.y = textObjectBounds.y + 1.0f;
2879                 }
2880                 else if (touchPoint.y >= (textObjectBounds.y + textObjectBounds.height))
2881                 {
2882                         cursorPoint.y = textObjectBounds.y + textObjectBounds.height - 1.0f;
2883                 }
2884                 else
2885                 {
2886                         cursorPoint.y = touchPoint.y;
2887                 }
2888
2889                 if (touchPoint.x <= textObjectBounds.x)
2890                 {
2891                         cursorPoint.x = textObjectBounds.x + 1.0f;
2892                 }
2893                 else if (touchPoint.x >= (textObjectBounds.x + textObjectBounds.width))
2894                 {
2895                         cursorPoint.x = textObjectBounds.x + textObjectBounds.width - 1.0f;
2896                 }
2897                 else
2898                 {
2899                         cursorPoint.x = touchPoint.x;
2900                 }
2901                 cursorPoint.y -= textObjectBounds.y;
2902                 cursorPoint.x -= textObjectBounds.x;
2903         }
2904         else
2905         {
2906                 return cursorPos;
2907         }
2908
2909         cursorPos = __pTextObject->GetTextIndexFromPosition(cursorPoint.x, cursorPoint.y, rowIndex, columnIndex, true);
2910
2911         return cursorPos;
2912 }
2913
2914 bool
2915 _EditPresenter::IsHorizontalDirection(const _TouchInfo& touchInfo)
2916 {
2917         if (touchInfo.GetTouchStatus() != _TOUCH_MOVED)
2918         {
2919                 return false;
2920         }
2921
2922         if (__isMovingCursorByTouchMove)
2923         {
2924                 return true;
2925         }
2926
2927         FloatRectangle absoluteEditRect = __pEdit->GetAbsoluteBoundsF(true);
2928         FloatPoint touchStartPoint = __pressedAbsolutePoint;
2929         //After internal touch core complete the float conversion, we need to change the code here
2930         FloatPoint touchPoint = touchInfo.GetCurrentPosition();
2931
2932         float movedWidth = touchStartPoint.x - touchPoint.x - absoluteEditRect.x;
2933         float movedHeight = touchStartPoint.y - touchPoint.y - absoluteEditRect.y;
2934         movedWidth = (movedWidth >= 0.0f) ? movedWidth : -(movedWidth);
2935         movedHeight = (movedHeight >= 0.0f) ? movedHeight : -(movedHeight);
2936
2937         if (movedWidth >= movedHeight * DIRECTION_DECISION_RATIO)
2938         {
2939                 return true;
2940         }
2941
2942         return false;
2943 }
2944
2945 bool
2946 _EditPresenter::IsInitialized(void) const
2947 {
2948         return __isInitialized;
2949 }
2950
2951 result
2952 _EditPresenter::CalculateCursorBounds(const FloatRectangle& textBounds, FloatRectangle& cursorBounds, int cursorPos)
2953 {
2954         float cursorWidth = 0.0f;
2955         float cursorHeight = 0.0f;
2956         float cursorAbsX = 0.0f;
2957         float cursorAbsY = 0.0f;
2958         float cursorRelativeX = 0.0f;
2959         float cursorRelativeY = 0.0f;
2960
2961         __pTextObject->SetBounds(textBounds);
2962
2963         if (cursorPos == -1)
2964         {
2965                 cursorPos = __pTextObject->GetCursorIndex();
2966         }
2967
2968         if (cursorPos != __cursorPos)
2969         {
2970                 if (__pTextObject->GetTextPositionInfoAt(cursorPos, cursorWidth, cursorHeight, cursorAbsX, cursorAbsY, cursorRelativeX, cursorRelativeY) != E_SUCCESS)
2971                 {
2972                         return E_SYSTEM;
2973                 }
2974         }
2975         else
2976         {
2977                 if (__pTextObject->GetTextPositionInfoAt(__rowCursorIndex, __columnCursorIndex, cursorWidth, cursorHeight, cursorAbsX, cursorAbsY, cursorRelativeX, cursorRelativeY) != E_SUCCESS)
2978                 {
2979                         return E_SYSTEM;
2980                 }
2981         }
2982
2983         cursorBounds.x = cursorRelativeX;
2984         cursorBounds.y = cursorRelativeY;
2985         float cursorWidthValue = 0.0f;
2986         GET_SHAPE_CONFIG(EDIT::CURSOR_WIDTH, __pEdit->GetOrientation(), cursorWidthValue);
2987         cursorBounds.width = cursorWidthValue;
2988         cursorBounds.height = cursorHeight;
2989
2990         if (cursorBounds.y == 0.0f)
2991         {
2992                 cursorBounds.y = __textObjectBounds.y;
2993         }
2994
2995         if (cursorBounds.height == 0.0f)
2996         {
2997                 cursorBounds.height = __textObjectBounds.height;
2998         }
2999
3000         if (cursorBounds.height == 0.0f)
3001         {
3002                 return E_SYSTEM;
3003         }
3004
3005         if (cursorBounds.y < textBounds.y)
3006         {
3007                 float cursorHeightDiff = textBounds.y - cursorBounds.y;
3008                 cursorBounds.y = textBounds.y;
3009                 cursorBounds.height -= cursorHeightDiff;
3010         }
3011
3012         if ((cursorBounds.y + cursorBounds.height > textBounds.y + textBounds.height) &&
3013                 (cursorBounds.y < textBounds.y + textBounds.height))
3014         {
3015                 float cursorHeightDiff = cursorBounds.y + cursorBounds.height - textBounds.y - textBounds.height;
3016                 if (cursorHeightDiff > 0.0f)
3017                 {
3018                         cursorBounds.height -= cursorHeightDiff;
3019                 }
3020                 else
3021                 {
3022                         cursorBounds.height += cursorHeightDiff;
3023                 }
3024         }
3025
3026         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
3027         {
3028                 if (__pTextObject->GetBlock() == false)
3029                 {
3030                         cursorBounds.x -= 1.0f;
3031                 }
3032
3033                 if (cursorBounds.x > textBounds.x + textBounds.width)
3034                 {
3035                         if (cursorBounds.x <= textBounds.x + textBounds.width + cursorBounds.width)
3036                         {
3037                                 cursorBounds.x = textBounds.x + textBounds.width;
3038                         }
3039                         else
3040                         {
3041                                 return E_SYSTEM;
3042                         }
3043                 }
3044
3045                 if (cursorBounds.x < textBounds.x)
3046                 {
3047                         if (cursorBounds.x > textBounds.x - cursorBounds.width)
3048                         {
3049                                 cursorBounds.x = textBounds.x;
3050                         }
3051                         else
3052                         {
3053                                 return E_SYSTEM;
3054                         }
3055                 }
3056         }
3057         else
3058         {
3059                 if (cursorBounds.x == textBounds.x + textBounds.width)
3060                 {
3061                         cursorBounds.x -= 1.0f;
3062                 }
3063                 else if (cursorBounds.x > textBounds.x + textBounds.width)
3064                 {
3065                         cursorBounds.x = textBounds.x + textBounds.width;
3066                         return E_SYSTEM;
3067                 }
3068
3069                 if (__pTextObject->GetBlock() == false)
3070                 {
3071                         cursorBounds.x -= 1.0f;
3072                         if (cursorBounds.x < textBounds.x)
3073                         {
3074                                 cursorBounds.x = textBounds.x;
3075                         }
3076                 }
3077         }
3078         __calculatedCursorBounds = cursorBounds;
3079         return E_SUCCESS;
3080 }
3081
3082 result
3083 _EditPresenter::CalculateCursorBounds(const FloatRectangle& textBounds, FloatRectangle& cursorBounds, int rowIndex, int columnIndex)
3084 {
3085         float cursorWidth = 0.0f;
3086         float cursorHeight = 0.0f;
3087         float cursorAbsX = 0.0f;
3088         float cursorAbsY = 0.0f;
3089         float cursorRelativeX = 0.0f;
3090         float cursorRelativeY = 0.0f;
3091
3092         __pTextObject->SetBounds(textBounds);
3093
3094         if (__pTextObject->GetTextPositionInfoAt(rowIndex, columnIndex, cursorWidth, cursorHeight, cursorAbsX, cursorAbsY, cursorRelativeX, cursorRelativeY) != E_SUCCESS)
3095         {
3096                 return E_SYSTEM;
3097         }
3098
3099         cursorBounds.x = cursorRelativeX;
3100         cursorBounds.y = cursorRelativeY;
3101         float cursorWidthValue = 0.0f;
3102         GET_SHAPE_CONFIG(EDIT::CURSOR_WIDTH, __pEdit->GetOrientation(), cursorWidthValue);
3103         cursorBounds.width = cursorWidthValue;
3104         cursorBounds.height = cursorHeight;
3105
3106         if (cursorBounds.y == 0.0f)
3107         {
3108                 cursorBounds.y = __textObjectBounds.y;
3109         }
3110
3111         if (cursorBounds.height == 0.0f)
3112         {
3113                 cursorBounds.height = __textObjectBounds.height;
3114         }
3115
3116         if (cursorBounds.height == 0.0f)
3117         {
3118                 return E_SYSTEM;
3119         }
3120
3121         if (cursorBounds.y < textBounds.y)
3122         {
3123                 float cursorHeightDiff = textBounds.y - cursorBounds.y;
3124                 cursorBounds.y = textBounds.y;
3125                 cursorBounds.height -= cursorHeightDiff;
3126         }
3127
3128         if ((cursorBounds.y + cursorBounds.height > textBounds.y + textBounds.height) &&
3129                 (cursorBounds.y < textBounds.y + textBounds.height))
3130         {
3131                 float cursorHeightDiff = cursorBounds.y + cursorBounds.height - textBounds.y - textBounds.height;
3132                 if (cursorHeightDiff > 0.0f)
3133                 {
3134                         cursorBounds.height -= cursorHeightDiff;
3135                 }
3136                 else
3137                 {
3138                         cursorBounds.height += cursorHeightDiff;
3139                 }
3140         }
3141
3142         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
3143         {
3144                 if (__pTextObject->GetBlock() == false)
3145                 {
3146                         cursorBounds.x -= 1.0f;
3147                 }
3148
3149                 if (cursorBounds.x > textBounds.x + textBounds.width)
3150                 {
3151                         if (cursorBounds.x <= textBounds.x + textBounds.width + cursorBounds.width)
3152                         {
3153                                 cursorBounds.x = textBounds.x + textBounds.width;
3154                         }
3155                         else
3156                         {
3157                                 return E_SYSTEM;
3158                         }
3159                 }
3160
3161                 if (cursorBounds.x < textBounds.x)
3162                 {
3163                         if (cursorBounds.x > textBounds.x - cursorBounds.width)
3164                         {
3165                                 cursorBounds.x = textBounds.x;
3166                         }
3167                         else
3168                         {
3169                                 return E_SYSTEM;
3170                         }
3171                 }
3172         }
3173         else
3174         {
3175                 if (cursorBounds.x == textBounds.x + textBounds.width)
3176                 {
3177                         cursorBounds.x -= 1.0f;
3178                 }
3179                 else if (cursorBounds.x > textBounds.x + textBounds.width)
3180                 {
3181                         cursorBounds.x = textBounds.x + textBounds.width;
3182                         return E_SYSTEM;
3183                 }
3184
3185                 if (__pTextObject->GetBlock() == false)
3186                 {
3187                         cursorBounds.x -= 1.0f;
3188                         if (cursorBounds.x < textBounds.x)
3189                         {
3190                                 cursorBounds.x = textBounds.x;
3191                         }
3192                 }
3193         }
3194         __calculatedCursorBounds = cursorBounds;
3195         return E_SUCCESS;
3196 }
3197
3198 result
3199 _EditPresenter::ScrollContents(float moveY)
3200 {
3201         int moveLine = 0;
3202         float firstDisplayY = 0.0f;
3203         float effectDistance = moveY;
3204
3205         float totalHeight = __pTextObject->GetTotalHeightF();
3206         float newFirstDisplayY = firstDisplayY = __pTextObject->GetFirstDisplayPositionYF();
3207         int currentCursorLine = 0;
3208
3209         if (__pTextObject->GetTextLength() < 1)
3210         {
3211                 return E_SYSTEM;
3212         }
3213
3214         if (__pScrollBar && __pScrollBar->GetScrollPosition() == 0 && effectDistance < 0.0f)
3215         {
3216                 if (__pFlickAnimationTimer)
3217                 {
3218                         StopFlickTimer();
3219                 }
3220
3221                 __pScrollBar->SetScrollVisibility(false);
3222
3223                 return E_SYSTEM;
3224         }
3225         else if (__pScrollBar && __pScrollBar->GetScrollPosition() != 0 && __pScrollBar->GetScrollPosition() == __previousScrollBarMaxPos && effectDistance > 0.0f)
3226         {
3227                 if (__pFlickAnimationTimer)
3228                 {
3229                         StopFlickTimer();
3230                 }
3231
3232                 __pScrollBar->SetScrollVisibility(false);
3233
3234                 return E_SYSTEM;
3235         }
3236
3237         if (__pTextObject->GetCursorIndex() == __pTextObject->GetTextLength())
3238         {
3239                 currentCursorLine = __pTextObject->GetTotalLineCount() - 1;
3240         }
3241         else
3242         {
3243                 currentCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
3244         }
3245
3246         if (currentCursorLine == -1)
3247         {
3248                 return E_SYSTEM;
3249         }
3250
3251         if (currentCursorLine < 0)
3252         {
3253                 currentCursorLine = 0;
3254         }
3255
3256         newFirstDisplayY += moveY;
3257
3258         if (newFirstDisplayY > (totalHeight - __textObjectBounds.height))
3259         {
3260                 newFirstDisplayY = totalHeight - __textObjectBounds.height;
3261         }
3262
3263         if (newFirstDisplayY < 0.0f)
3264         {
3265                 newFirstDisplayY = 0.0f;
3266         }
3267
3268         moveLine = __pTextObject->GetLineIndexAtPositionY(newFirstDisplayY);
3269
3270         __pTextObject->SetFirstDisplayLineIndex(moveLine);
3271         __pTextObject->SetFirstDisplayPositionY(newFirstDisplayY);
3272
3273         __isCursorOpaque = false;
3274         if (__isCopyPasteManagerExist)
3275         {
3276                 __pCopyPasteManager->AdjustBounds();
3277         }
3278
3279         return E_SUCCESS;
3280 }
3281
3282 bool
3283 _EditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
3284 {
3285         if ((&source != __pEdit) || (__pEdit->GetEnableState() == false))
3286         {
3287                 return false;
3288         }
3289
3290         if (__isCopyPasteManagerExist)
3291         {
3292                 __pCopyPasteManager->ReleaseCopyPastePopup();
3293         }
3294
3295         __isTouchPressed = true;
3296         __isTouchReleaseSkipped = false;
3297
3298         __pScrollEffect->previousY = _CoordinateSystemUtils::ConvertToFloat(touchInfo.GetCurrentPosition().y);
3299         __pScrollEffect->currentY = _CoordinateSystemUtils::ConvertToFloat(touchInfo.GetCurrentPosition().y);
3300         __pScrollEffect->previousX = _CoordinateSystemUtils::ConvertToFloat(touchInfo.GetCurrentPosition().x);
3301         __pScrollEffect->currentX = _CoordinateSystemUtils::ConvertToFloat(touchInfo.GetCurrentPosition().x);
3302
3303         __pScrollEffect->previousAbsX = _CoordinateSystemUtils::ConvertToFloat(__pEdit->GetAbsoluteBoundsF(true).x + touchInfo.GetCurrentPosition().x);
3304         __pScrollEffect->currentAbsX = _CoordinateSystemUtils::ConvertToFloat(__pEdit->GetAbsoluteBoundsF(true).x + touchInfo.GetCurrentPosition().x);
3305         __pScrollEffect->previousAbsY = _CoordinateSystemUtils::ConvertToFloat(__pEdit->GetAbsoluteBoundsF(true).y + touchInfo.GetCurrentPosition().y);
3306         __pScrollEffect->currentAbsY = _CoordinateSystemUtils::ConvertToFloat(__pEdit->GetAbsoluteBoundsF(true).y + touchInfo.GetCurrentPosition().y);
3307
3308         __pScrollEffect->cursorPosition = GetCursorPosition();
3309
3310         FloatRectangle absoluteEditRect = __pEdit->GetAbsoluteBoundsF(true);
3311
3312         __pressedPoint = touchInfo.GetCurrentPosition();
3313         __pressedAbsolutePoint.x = __pressedPoint.x + absoluteEditRect.x;
3314         __pressedAbsolutePoint.y = __pressedPoint.y + absoluteEditRect.y;
3315
3316         if (IsViewModeEnabled())
3317         {
3318                 int cutLinkIndex = -1;
3319
3320                 __pTextObject->ResetAllCutLinkElementsState();
3321
3322                 cutLinkIndex = __pTextObject->GetCutLinkIndexFromPositionData(__pressedPoint.x - __textObjectBounds.x, __pressedPoint.y - __textObjectBounds.y);
3323
3324                 if (cutLinkIndex != -1)
3325                 {
3326                         __pTextObject->ChangeCutLinkState(cutLinkIndex, true);
3327                 }
3328         }
3329
3330         if (__pEdit->GetEditStyle() & EDIT_STYLE_CLEAR && __pTextString->GetLength() > 0 && __isClearIconVisible)
3331         {
3332                 if ((__pressedPoint.x >= __clearIconBounds.x) && (__pressedPoint.x <= __clearIconBounds.x + __clearIconBounds.width)
3333                         && (__pressedPoint.y >= __clearIconBounds.y) && (__pressedPoint.y <= __clearIconBounds.y + __clearIconBounds.height)) // Clear Icon Pressed
3334                 {
3335                         __isClearIconPressed = true;
3336                         __pEdit->SetTouchPressThreshold(TOUCH_PRESS_THRESHOLD_IN_CLEAR_AREA);
3337                 }
3338         }
3339         StopFlickTimer();
3340
3341         __pEdit->Invalidate();
3342
3343         return true;
3344 }
3345
3346 bool
3347 _EditPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
3348 {
3349         InitializeCopyPasteManager();
3350
3351         if ((&source != __pEdit) || (__pEdit->GetEnableState() == false))
3352         {
3353                 return false;
3354         }
3355
3356         if (__isClearIconPressed)
3357         {
3358                 __isClearIconPressed = false;
3359                 __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
3360         }
3361
3362         __isTouchPressed = false;
3363         __isMovingCursorByTouchMove = false;
3364
3365         if (__isTouchReleaseSkipped || __isTouchMoving)
3366         {
3367                 __isTouchReleaseSkipped = false;
3368                 FadeOutScrollBar();
3369                 __isTouchMoving = false;
3370         }
3371
3372         if (__isScrollBarVisible && __pScrollBar)
3373         {
3374                 if (__pScrollBar->IsVisible())
3375                 {
3376                         __pScrollBar->SetScrollVisibility(false);
3377                 }
3378                 __isScrollBarVisible = false;
3379         }
3380
3381         __isTouchMoving = false;
3382         __pEdit->Invalidate();
3383
3384         return true;
3385 }
3386
3387 bool
3388 _EditPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
3389 {
3390         if (__dragAndDropStarted)
3391         {
3392                 ResetDragAndDrop();
3393                 return true;
3394         }
3395
3396         __isTouchLongPressed = false;
3397
3398         if (__isCopyPasteManagerExist)
3399         {
3400                 if (__isTouchPressed && !__isCopyPastePopupMoving)
3401                 {
3402                         InitializeCopyPasteManager();
3403                         if (__isClearIconPressed)
3404                         {
3405                                 FloatPoint touchPoint = touchInfo.GetCurrentPosition();
3406                                 __isClearIconPressed = false;
3407                                 __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
3408                                 if ((touchPoint.x >= __clearIconBounds.x) && (touchPoint.x <= __clearIconBounds.x + __clearIconBounds.width)
3409                                         && (touchPoint.y >= __clearIconBounds.y) && (touchPoint.y <= __clearIconBounds.y + __clearIconBounds.height))
3410                                 {
3411                                         ClearText();
3412                                         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3413                                         __isMovingCursorByTouchMove = false;
3414                                         __pEdit->Invalidate();
3415                                 }
3416                         }
3417
3418                         __isTouchPressed = false;
3419                         __isCopyPastePopupMoving = false;
3420
3421                         if (IsCurrentFocused())
3422                         {
3423                                 return true;
3424                         }
3425                 }
3426                 else
3427                 {
3428                         if (!IsCurrentFocused())
3429                         {
3430                                 __pEdit->SetFocused();
3431                         }
3432
3433                         FadeOutScrollBar(); // Fade out scrollbar when copypaste popup is moving.
3434                         if (__needToCreateCopyPastePopup)
3435                         {
3436                                 __pCopyPasteManager->CreateCopyPastePopup();
3437                         }
3438                         __needToCreateCopyPastePopup = false;
3439                         __pCopyPasteManager->Show();
3440
3441                         __isTouchPressed = false;
3442                         __isCopyPastePopupMoving = false;
3443
3444                         return true;
3445                 }
3446         }
3447
3448         if ((&source != __pEdit) || (__pEdit->GetEnableState() == false))
3449         {
3450                 return false;
3451         }
3452
3453         int cutLinkIndex = -1;
3454         FloatRectangle clientBounds;
3455         FloatPoint touchPoint = touchInfo.GetCurrentPosition();
3456
3457         if (__isClearIconPressed)
3458         {
3459                 __isClearIconPressed = false;
3460                 __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
3461
3462                 if ((touchPoint.x >= __clearIconBounds.x) && (touchPoint.x <= __clearIconBounds.x + __clearIconBounds.width)
3463                         && (touchPoint.y >= __clearIconBounds.y) && (touchPoint.y <= __clearIconBounds.y + __clearIconBounds.height))
3464                 {
3465                         ClearText();
3466                         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3467                         __isTouchPressed = false;
3468                         __isMovingCursorByTouchMove = false;
3469                         __pEdit->Invalidate();
3470
3471                         __isTouchMoving = false;
3472                         if (IsCurrentFocused() || GetSearchBarFlag())
3473                         {
3474                                 return true;
3475                         }
3476                 }
3477         }
3478
3479         if (!__isCopyPasteManagerExist)
3480         {
3481                 __isTextBlocked = false;
3482         }
3483         __isTouchPressed = false;
3484         __isMovingCursorByTouchMove = false;
3485
3486         if (__isTouchReleaseSkipped)
3487         {
3488                 __isTouchReleaseSkipped = false;
3489                 FadeOutScrollBar();
3490                 __isTouchMoving = false;
3491                 __pEdit->Invalidate();
3492
3493                 return true;
3494         }
3495
3496         if (__isTouchMoving && __isInputConnectionBound == false)
3497         {
3498                 FadeOutScrollBar();
3499                 __isTouchMoving = false;
3500                 __isTouchReleaseSkipped = false;
3501                 __pEdit->Invalidate();
3502
3503                 return true;
3504         }
3505
3506         if (IsViewModeEnabled())
3507         {
3508                 __pEdit->SetFocused();
3509
3510                 __pTextObject->ResetAllCutLinkElementsState();
3511
3512                 cutLinkIndex = __pTextObject->GetCutLinkIndexFromPositionData(touchPoint.x - __textObjectBounds.x, touchPoint.y - __textObjectBounds.y);
3513
3514                 if (cutLinkIndex != -1)
3515                 {
3516                         TextCutLink* pCutLinkObject = dynamic_cast<TextCutLink*>(__pTextObject->GetCutLinkElementAtCutLinkElementIndex(cutLinkIndex));
3517                         if (pCutLinkObject == null)
3518                         {
3519                                 return true;
3520                         }
3521
3522                         String cutLinkString(pCutLinkObject->GetText());
3523                         LinkType baseLinkType = pCutLinkObject->GetCutLinkType();
3524
3525                         // Send Ui Link Event
3526                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEdit);
3527                         __pEdit->SendLinkEvent(cutLinkString, baseLinkType, cutLinkString);
3528                 }
3529         }
3530
3531         clientBounds = __pEdit->GetBoundsF();
3532         clientBounds.x = 0.0f;
3533         clientBounds.y = 0.0f;
3534         touchPoint = touchInfo.GetCurrentPosition();
3535         if (clientBounds.Contains(touchPoint))
3536         {
3537                 int rowIndex;
3538                 int columnIndex;
3539                 int cursorPos = GetCursorPositionAt(touchPoint, rowIndex,columnIndex);
3540                 if (cursorPos != -1)
3541                 {
3542                         if (__isInputConnectionBound == true && __isTextComposing == true)
3543                         {
3544                                 __pInputConnection->FinishTextComposition();
3545                         }
3546                         if (!__isCopyPasteManagerExist) // Copy&Paste
3547                         {
3548                                 if ((__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE) == true && IsCurrentFocused() == false)
3549                                 {
3550                                         __isCursorChanged = true;
3551                                 }
3552                                 else
3553                                 {
3554                                         SetCursorPosition(cursorPos, rowIndex, columnIndex);
3555                                 }
3556                         }
3557                 }
3558                 else
3559                 {
3560                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE) == false)
3561                         {
3562                                 if (__isInputConnectionBound == true && __isTextComposing == true)
3563                                 {
3564                                         __pInputConnection->FinishTextComposition();
3565                                 }
3566                                 SetCursorPosition(GetTextLength());
3567                         }
3568                 }
3569
3570                 FadeOutScrollBar();
3571                 if (!__isCopyPasteManagerExist && !__pFlickAnimationTimer)
3572                 {
3573                         bool tokenEditting = false;
3574                         bool needToCreatePopup = true;
3575                         if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
3576                         {
3577                                 _TokenEditPresenter* pTokenEditPresenter = dynamic_cast < _TokenEditPresenter* >(this);
3578                                 if (pTokenEditPresenter)
3579                                 {
3580                                         if (pTokenEditPresenter->GetSelectedTokenIndex() != -1)
3581                                         {
3582                                                 tokenEditting = true;
3583                                         }
3584                                 }
3585                         }
3586
3587                         if (!__isUSBKeyboardConnected && !__isKeypadExist && !IsViewModeEnabled() && IsKeypadEnabled())
3588                         {
3589                                 needToCreatePopup = false;
3590                         }
3591
3592                         if (IsViewModeEnabled())
3593                         {
3594                                 needToCreatePopup = false;
3595                         }
3596                         _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
3597                         SysTryReturn(NID_UI_CTRL, pAccessibilityManager, false, E_SYSTEM, "pAccessibilityManager is null");
3598                         if (pAccessibilityManager->IsActivated())
3599                         {
3600                                 needToCreatePopup = false;
3601                         }
3602
3603                         if (IsCurrentFocused() && !tokenEditting && needToCreatePopup)
3604                         {
3605                                 if (__pPasswordTimer)
3606                                 {
3607                                         ChangePasswordToEchoCharacter(__pTextBuffer, __echoChar);
3608                                         StopPasswordTimer();
3609                                 }
3610                                 __pCopyPasteManager = new (std::nothrow) _EditCopyPasteManager(*__pEdit);
3611                                 SysTryReturn(NID_UI_CTRL, __pCopyPasteManager != null, false, E_SYSTEM, "Unable to create _EditCopyPasteManager instance.");
3612                                 __pCopyPasteManager->AddCopyPasteEventListener(*this);
3613                                 UpdateComponentInformation();
3614                                 __pCopyPasteManager->DestroyCopyPasteMagnifier();
3615                                 __pCopyPasteManager->Show();
3616                                 __isCopyPasteManagerExist = true;
3617                         }
3618                 }
3619
3620                 if (cutLinkIndex < 0)
3621                 {
3622                         CheckUSBKeyboardStatus();
3623
3624                         if (__isUSBKeyboardConnected)
3625                         {
3626                                 if (!__isInputConnectionBound)
3627                                 {
3628                                         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
3629                                         {
3630                                                 if (IsViewModeEnabled() == false)
3631                                                 {
3632                                                         if (IsCurrentFocused())
3633                                                         {
3634                                                                 ShowKeypad(false);
3635                                                         }
3636                                                         else
3637                                                         {
3638                                                                 __pEdit->SetFocused();
3639                                                         }
3640                                                 }
3641                                         }
3642                                         else
3643                                         {
3644                                                 if (__pEditModel->IsViewModeEnabled() == false) //in case of fullscreen style, should check editModel's viewMode
3645                                                 {
3646                                                         ShowFullscreenKeypad();
3647                                                 }
3648                                         }
3649                                 }
3650                         }
3651                         else
3652                         {
3653                                 if (!__isKeypadExist || !__isInputConnectionBound)
3654                                 {
3655                                         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
3656                                         {
3657                                                 if (IsViewModeEnabled() == false)
3658                                                 {
3659                                                         if (IsCurrentFocused())
3660                                                         {
3661                                                                 ShowKeypad(false);
3662                                                         }
3663                                                         else
3664                                                         {
3665                                                                 __pEdit->SetFocused();
3666                                                         }
3667                                                 }
3668                                         }
3669                                         else
3670                                         {
3671                                                 if (__pEditModel->IsViewModeEnabled() == false) //in case of fullscreen style, should check editModel's viewMode
3672                                                 {
3673                                                         ShowFullscreenKeypad();
3674                                                 }
3675                                         }
3676                                 }
3677                         }
3678                 }
3679         }
3680
3681         if (__isScrollBarVisible && __pScrollBar)
3682         {
3683                 if (__pScrollBar->IsVisible())
3684                 {
3685                         __pScrollBar->SetScrollVisibility(false);
3686                 }
3687                 __isScrollBarVisible = false;
3688         }
3689
3690         __isTouchMoving = false;
3691         __pEdit->Invalidate();
3692
3693         if (GetSearchBarFlag())
3694         {
3695                 return false;
3696         }
3697
3698         return true;
3699 }
3700
3701 bool
3702 _EditPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
3703 {
3704         if (__dragAndDropStarted)
3705         {
3706                 _Window* pDragWindow = __pEdit->GetDragWindow();
3707                 if (pDragWindow)
3708                 {
3709                         FloatPoint dragPoint = touchInfo.GetCurrentPosition();
3710                         dragPoint.x += __pEdit->GetAbsoluteBoundsF(true).x;
3711                         dragPoint.y += __pEdit->GetAbsoluteBoundsF(true).y;
3712                         pDragWindow->SetPosition(FloatPoint(dragPoint.x - pDragWindow->GetBoundsF().width/2.0f, dragPoint.y - pDragWindow->GetBoundsF().height/2.0f));
3713                 }
3714                 return true;
3715         }
3716
3717         if ((&source != __pEdit) || (__pEdit->GetEnableState() == false))
3718         {
3719                 return false;
3720         }
3721
3722         FloatPoint touchPoint = touchInfo.GetCurrentPosition();
3723
3724         if (__isClearIconPressed)
3725         {
3726                 if ((touchPoint.x < __clearIconBounds.x) || (touchPoint.x > __clearIconBounds.x + __clearIconBounds.width)
3727                         || (touchPoint.y < __clearIconBounds.y) || (touchPoint.y > __clearIconBounds.y + __clearIconBounds.height))
3728                 {
3729                         __isClearIconPressed = false;
3730                         __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
3731                         __pEdit->Invalidate();
3732                 }
3733         }
3734
3735         if (__isCopyPasteManagerExist)
3736         {
3737                 if (!IsBlocked() && GetTextLength() > 0 && __isTouchLongPressed)
3738                 {
3739                         int cursorPos = -1; 
3740                         int rowIndex = -1;
3741                         int columnIndex = -1;
3742                         FloatPoint touchPoint = touchInfo.GetCurrentPosition();
3743                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__cursorPos);
3744                         int totalLine = __pTextObject->GetTotalLineCount();
3745                         float firstDisplayY = __pTextObject->GetFirstDisplayPositionYF();
3746                         float totalHeight = __pTextObject->GetTotalHeightF();
3747
3748                         if (touchPoint.x < __textObjectBounds.x)
3749                         {
3750                                 touchPoint.x = __textObjectBounds.x;
3751                         }
3752                         if (touchPoint.x > __textObjectBounds.x + __textObjectBounds.width)
3753                         {
3754                                 touchPoint.x = __textObjectBounds.x + __textObjectBounds.width;
3755                         }
3756                         if (__textObjectBounds.y > touchPoint.y)
3757                         {
3758                                 if (totalLine == 1 || firstDisplayY == 0.0f) // whether need to scroll the text or not
3759                                 {
3760                                         touchPoint.y = __textObjectBounds.y; //not need to scroll the text.
3761                                 }
3762                         }
3763                         if (__textObjectBounds.y + __textObjectBounds.height < touchPoint.y)
3764                         {
3765                                 if (totalLine == 1 || (totalHeight - firstDisplayY < __textObjectBounds.height) || curCursorLine == (totalLine - 1)) // || pTextObject->IsDisplayedLastLine()) // whether need to scroll the text or not
3766                                 {
3767                                         touchPoint.y = __textObjectBounds.y + __textObjectBounds.height; // check TextObject
3768                                 }
3769                         }
3770
3771                         if(!(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE))
3772                         {
3773                                 if (totalHeight < __textObjectBounds.height)
3774                                 {
3775                                         if (totalHeight < touchPoint.y)
3776                                         {
3777                                                 touchPoint.y = totalHeight;
3778                                         }
3779                                 }
3780                         }
3781                         cursorPos = GetCursorPositionAt(touchPoint, rowIndex, columnIndex);
3782                         if (cursorPos == -1)
3783                         {
3784                                 FloatRectangle cursorRect(0.0f, 0.0f, 0.0f, 0.0f);
3785                                 CalculateCursorBounds(__textObjectBounds, cursorRect, __rowCursorIndex, __columnCursorIndex);
3786                                 if (totalLine != 1)
3787                                 {
3788                                         if (touchPoint.y > (cursorRect.y + cursorRect.height))
3789                                         {
3790                                                 if (curCursorLine < totalLine - 1)
3791                                                 {
3792                                                         int offset = __cursorPos - __pTextObject->GetFirstTextIndexAt(curCursorLine);
3793                                                         int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine+1);
3794                                                         cursorPos = offset + firstTextIndex;
3795                                                         int textLength = __pTextObject->GetTextLengthAt(curCursorLine+1);
3796                                                         if (offset > textLength)
3797                                                         {
3798                                                                 cursorPos = firstTextIndex+textLength;
3799                                                         }
3800                                                 }
3801                                         }
3802                                         else
3803                                         {
3804                                                 if (curCursorLine !=0)
3805                                                 {
3806                                                         if (__rowCursorIndex == 0)
3807                                                         {
3808                                                                 cursorPos = -1;
3809                                                         }
3810                                                         else
3811                                                         {
3812                                                                 int offset = __cursorPos - __pTextObject->GetFirstTextIndexAt(curCursorLine);
3813                                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine-1);
3814                                                                 cursorPos = offset + firstTextIndex;
3815                                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine-1);
3816                                                                 if (offset > textLength)
3817                                                                 {
3818                                                                         cursorPos = firstTextIndex+textLength;
3819                                                                 }
3820                                                         }
3821                                                 }
3822                                         }
3823                                 }
3824                                 if (cursorPos == -1)
3825                                 {
3826                                         return true;
3827                                 }
3828                                 SetCursorPosition(cursorPos);
3829                         }
3830                         else
3831                         {
3832                                 SetCursorPosition(cursorPos, rowIndex, columnIndex);
3833                         }
3834                         ScrollPanelToCursorPosition(true);
3835                         __pTextObject->SetFirstDisplayLineIndexFromTextIndex(cursorPos);
3836                         __pCopyPasteManager->Show();
3837                         if (!__isClearIconPressed)
3838                         {
3839                                 __isCopyPastePopupMoving = true;
3840                         }
3841                         return true;
3842                 }
3843                 else
3844                 {
3845                         __pCopyPasteManager->Show();
3846                         if (!__isClearIconPressed)
3847                         {
3848                                 __isCopyPastePopupMoving = true;
3849                         }
3850                 }
3851         }
3852
3853         if (__isTouchMoving == false && IsHorizontalDirection(touchInfo))
3854         {
3855                 if (__isCopyPasteManagerExist && IsBlocked())
3856                 {
3857                         return true;
3858                 }
3859
3860                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
3861                 {
3862                         float   horizontalGap = touchInfo.GetCurrentPosition().x - __pScrollEffect->currentX;
3863                         FloatRectangle lineBounds = __pTextObject->GetBoundsAtLineF(0);
3864                         float   textDisplayPositionX = __pTextObject->GetFirstDisplayPositionXF();
3865                         float   newTextDisplayPositionX = 0;
3866
3867                         if (horizontalGap < 0.0f && lineBounds.width - textDisplayPositionX > __textObjectBounds.width)
3868                         {
3869                                 newTextDisplayPositionX = textDisplayPositionX - horizontalGap;
3870
3871                                 if (newTextDisplayPositionX >  lineBounds.width - __textObjectBounds.width)
3872                                 {
3873                                         newTextDisplayPositionX = lineBounds.width - __textObjectBounds.width;
3874                                 }
3875
3876                                 __pScrollEffect->previousX = __pScrollEffect->currentX;
3877                                 __pScrollEffect->currentX = touchInfo.GetCurrentPosition().x;
3878                                 __isMovingCursorByTouchMove = true;
3879                                 __isTouchReleaseSkipped = true;
3880                                 StopCursorTimer();
3881
3882                                 __pTextObject->SetFirstDisplayPositionX(newTextDisplayPositionX);
3883                                 __pEdit->Invalidate();
3884                                 return true;
3885                         }
3886                         if (horizontalGap > 0.0f && textDisplayPositionX > 0)
3887                         {
3888                                 newTextDisplayPositionX = textDisplayPositionX - horizontalGap;
3889                                 if (newTextDisplayPositionX < 0)
3890                                 {
3891                                         newTextDisplayPositionX = 0;
3892                                 }
3893
3894                                 __pScrollEffect->previousX = __pScrollEffect->currentX;
3895                                 __pScrollEffect->currentX = touchInfo.GetCurrentPosition().x;
3896                                 __isMovingCursorByTouchMove = true;
3897                                 __isTouchReleaseSkipped = true;
3898                                 StopCursorTimer();
3899
3900                                 __pTextObject->SetFirstDisplayPositionX(newTextDisplayPositionX);
3901                                 __pEdit->Invalidate();
3902                                 return true;
3903                         }
3904                 }
3905                 else
3906                 {
3907                         int newIndex = -1;
3908                         FloatRectangle fromBounds;
3909                         FloatRectangle toBounds;
3910                         CalculateCursorBounds(__textObjectBounds, fromBounds);
3911                         newIndex = GetCursorPositionAt(touchInfo.GetCurrentPosition());
3912                         if (newIndex != -1)
3913                         {
3914                                 if (Math::Abs(newIndex - __cursorPos) > 3)
3915                                 {
3916                                         return true;
3917                                 }
3918
3919                                 CalculateCursorBounds(__textObjectBounds, toBounds, newIndex);
3920                                 __isCursorChanged = true;
3921                                 SetCursorPosition(newIndex);
3922
3923                                 __isMovingCursorByTouchMove = true;
3924                                 __isTouchReleaseSkipped = true;
3925
3926                                 StopCursorTimer();
3927                                 MoveCursor(fromBounds, toBounds);
3928                                 __pEdit->Invalidate();
3929
3930                                 return true;
3931                         }
3932
3933                                 if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
3934                         {
3935                                 float   horizontalGap = touchInfo.GetCurrentPosition().x - fromBounds.x;
3936                                 FloatDimension currentCharacterDimension;
3937                                 if (horizontalGap > 0.0f && __cursorPos < GetTextLength())
3938                                 {
3939                                         currentCharacterDimension = __pTextObject->GetTextExtentF(__cursorPos, 1);
3940                                         if (horizontalGap >= currentCharacterDimension.width)
3941                                         {
3942                                                 SetCursorPosition(__cursorPos+1);
3943                                                 __pEdit->Invalidate();
3944                                                 return true;
3945                                         }
3946                                 }
3947                                 if (horizontalGap < 0.0f && __cursorPos > 0)
3948                                 {
3949                                         currentCharacterDimension = __pTextObject->GetTextExtentF(__cursorPos-1, 1);
3950                                         if (Math::Abs(horizontalGap) >= currentCharacterDimension.width)
3951                                         {
3952                                                 SetCursorPosition(__cursorPos-1);
3953                                                 __pEdit->Invalidate();
3954                                                 return true;
3955                                         }
3956                                 }
3957                         }
3958                 }
3959                 if (__isMovingCursorByTouchMove)
3960                 {
3961                         return true;
3962                 }
3963         }
3964
3965         float totalHeight = __pTextObject->GetTotalHeightF();
3966
3967         if (__textObjectBounds.height >= totalHeight)
3968         {
3969                 __isTouchMoving = true;
3970                 __isTouchReleaseSkipped = true;
3971                 return false;
3972         }
3973
3974         if ((touchInfo.GetCurrentPosition().y == __pScrollEffect->currentY) ||
3975                 (Math::Abs(touchInfo.GetCurrentPosition().y - __pScrollEffect->previousY) < MOVE_SKIP_DECISION_RANGE))
3976         {
3977                 return true;
3978         }
3979
3980         __pScrollEffect->previousY = __pScrollEffect->currentY;
3981         __pScrollEffect->currentY = touchInfo.GetCurrentPosition().y;
3982
3983         __pScrollEffect->previousAbsY = __pScrollEffect->currentAbsY;
3984         __pScrollEffect->currentAbsY = _CoordinateSystemUtils::ConvertToFloat(__pEdit->GetAbsoluteBoundsF(true).y + touchInfo.GetCurrentPosition().y);
3985
3986         float moveGap = __pScrollEffect->previousAbsY - __pScrollEffect->currentAbsY;
3987
3988         if (__isMovingCursorByTouchMove)
3989         {
3990                 __isMovingCursorByTouchMove = false;
3991         }
3992
3993         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL) && !(__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN))
3994         {
3995                 if (__pScrollBar)
3996                 {
3997                         if (totalHeight > __textObjectBounds.height)
3998                         {
3999                                 __pScrollBar->SetScrollVisibility(true);
4000                         }
4001                         else
4002                         {
4003                                 __pScrollBar->SetScrollVisibility(false);
4004                         }
4005                 }
4006         }
4007
4008         result returnResult = ScrollContents(moveGap);
4009
4010         __isCursorChanged = false;
4011         __isTouchMoving = true;
4012         DrawText();
4013         DrawScrollBar();
4014
4015         if (returnResult == E_SUCCESS)
4016         {
4017                 return true;
4018         }
4019         else
4020         {
4021                 __isTouchReleaseSkipped = true;
4022                 return false;
4023         }
4024 }
4025
4026 bool
4027 _EditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
4028 {
4029         result r = E_SUCCESS;
4030         _KeyCode keyCode = keyInfo.GetKeyCode();
4031         int textLength = 0;
4032         int start = 0;
4033         int end = 0;
4034         FloatRectangle panelAbsBounds(0.0f, 0.0f, 0.0f, 0.0f);
4035         FloatRectangle absCursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
4036
4037         if (__dragAndDropStarted)
4038         {
4039                 if (keyCode == _KEY_ESC)
4040                 {
4041                         ResetDragAndDrop();
4042                 }
4043                 return true;
4044         }
4045
4046         _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
4047         SysTryReturn(NID_UI_CTRL, pAccessibilityManager, false, E_SYSTEM, "pAccessibilityManager is null");
4048
4049         if (__pEditModel->IsViewModeEnabled() == false)
4050         {
4051                 if (__pEdit->GetInputStyle() == INPUT_STYLE_FULLSCREEN)
4052                 {
4053                         if (_KEY_ENTER == keyCode)
4054                         {
4055                                 CheckUSBKeyboardStatus();
4056                                 if (__isUSBKeyboardConnected)
4057                                 {
4058                                         ShowFullscreenKeypad();
4059                                         return true;
4060                                 }
4061                         }
4062                         return false;
4063                 }
4064         }
4065         else
4066         {
4067                 return false;
4068         }
4069
4070         if (__isUSBKeyboardConnected && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL) && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_SHIFT))
4071         {
4072                 if ((keyCode == _KEY_LEFT) || (keyCode == _KEY_RIGHT))
4073                 {
4074                         if (!__isCopyPasteManagerExist)
4075                         {
4076                                 if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
4077                                 {
4078                                         _TokenEditPresenter* pTokenEditPresenter = dynamic_cast < _TokenEditPresenter* >(this);
4079                                         if (pTokenEditPresenter)
4080                                         {
4081                                                 if (pTokenEditPresenter->GetSelectedTokenIndex() != -1)
4082                                                 {
4083                                                         return true;
4084                                                 }
4085                                         }
4086                                 }
4087                                 SetBlockRangeWithCtrlShiftArrowkey(keyCode);
4088                                 return true;
4089                         }
4090                         else
4091                         {
4092                                 if (__pCopyPasteManager->IsCopyPasteSingleHandleExist())
4093                                 {
4094                                         InitializeCopyPasteManager();
4095                                         SetBlockRangeWithShiftArrowkey(keyCode);
4096                                 }
4097                                 return true;
4098                         }
4099                 }
4100         }
4101         else    if (__isUSBKeyboardConnected && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL))
4102         {
4103                 switch (keyCode)
4104                 {
4105                         case _KEY_A:
4106                                 FinishTextComposition();
4107
4108                                 if (__isCopyPasteManagerExist)
4109                                 {
4110                                         InitializeCopyPasteManager();
4111                                 }
4112
4113                                 textLength = __pEdit->GetTextLength();
4114                                 if (!textLength)
4115                                 {
4116                                         return true;
4117                                 }
4118                                 __pEdit->SetBlockRange(0, textLength);
4119                                 r = __pEdit->SendTextBlockEvent(0, textLength);
4120                                 UpdateComponentInformation();
4121                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4122
4123                                 if (!pAccessibilityManager->IsActivated())
4124                                 {
4125                                         __pCopyPasteManager = new (std::nothrow) _EditCopyPasteManager(*__pEdit);
4126                                         SysTryReturn(NID_UI_CTRL, __pCopyPasteManager != null, true, E_OUT_OF_MEMORY, "Memory allocation failed.");
4127                                         __pCopyPasteManager->AddCopyPasteEventListener(*this);
4128                                         __pCopyPasteManager->CreateCopyPastePopup();
4129                                         __pCopyPasteManager->Show();
4130                                         __isCopyPasteManagerExist = true;
4131                                 }
4132
4133                                 break;
4134                         case _KEY_C:
4135                                 textLength = __pEdit->GetTextLength();
4136                                 if (!textLength)
4137                                 {
4138                                         return true;
4139                                 }
4140                                 CopyText();
4141                                 if (__isCopyPasteManagerExist)
4142                                 {
4143                                         InitializeCopyPasteManager();
4144                                 }
4145                                 break;
4146                         case _KEY_X:
4147                                 textLength = __pEdit->GetTextLength();
4148                                 if (!textLength)
4149                                 {
4150                                         return true;
4151                                 }
4152                                 CutText();
4153                                 if (__isCopyPasteManagerExist)
4154                                 {
4155                                         InitializeCopyPasteManager();
4156                                 }
4157                                 break;
4158                         case _KEY_V:
4159                                 PasteText();
4160                                 if (__isCopyPasteManagerExist)
4161                                 {
4162                                         InitializeCopyPasteManager();
4163                                 }
4164                                 break;
4165                         case _KEY_HOME_BUTTON:
4166                                 if (__isCopyPasteManagerExist)
4167                                 {
4168                                         InitializeCopyPasteManager();
4169                                 }
4170                                 if (__cursorPos != 0)
4171                                 {
4172                                         SetCursorPosition(0);
4173                                 }
4174                                 else
4175                                 {
4176                                         return true;
4177                                 }
4178                                 break;
4179                         case _KEY_END_BUTTON:
4180                                 if (__isCopyPasteManagerExist)
4181                                 {
4182                                         InitializeCopyPasteManager();
4183                                 }
4184                                 if (__cursorPos != GetTextLength())
4185                                 {
4186                                         SetCursorPosition(GetTextLength());
4187                                 }
4188                                 else
4189                                 {
4190                                         return true;
4191                                 }
4192                                 break;
4193                         case _KEY_LEFT:
4194                                 if (__isCopyPasteManagerExist)
4195                                 {
4196                                         InitializeCopyPasteManager();
4197                                 }
4198                                 if (__cursorPos == 0)
4199                                 {
4200                                         return true;
4201                                 }
4202                                 GetWordPosition(__cursorPos, start, end);
4203                                 if (__cursorPos != start)
4204                                 {
4205                                         SetCursorPosition(start);
4206                                 }
4207                                 else
4208                                 {
4209                                         GetWordPosition(start-1, start, end);
4210                                         SetCursorPosition(start);
4211                                 }
4212                                 break;
4213                         case _KEY_RIGHT:
4214                                 if (__isCopyPasteManagerExist)
4215                                 {
4216                                         InitializeCopyPasteManager();
4217                                 }
4218                                 if (__cursorPos == GetTextLength())
4219                                 {
4220                                         return true;
4221                                 }
4222                                 GetWordPosition(__cursorPos, start, end);
4223                                 if (__cursorPos != end)
4224                                 {
4225                                         SetCursorPosition(end);
4226                                 }
4227                                 else
4228                                 {
4229                                         GetWordPosition(end+1, start, end);
4230                                         SetCursorPosition(end);
4231                                 }
4232                                 break;
4233                         default:
4234                                 return true;
4235                 }
4236                 if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4237                 {
4238                         DrawText();
4239                 }
4240                 else
4241                 {
4242                         __pEdit->Invalidate();
4243                 }
4244
4245                 return true;
4246         }
4247         else if (__isUSBKeyboardConnected && keyInfo.GetKeyModifier() & _KEY_MODIFIER_SHIFT)
4248         {
4249                 if (!__isCopyPasteManagerExist)
4250                 {
4251                         if ((keyCode == _KEY_LEFT) || (keyCode == _KEY_UP) || (keyCode == _KEY_DOWN) || (keyCode == _KEY_RIGHT))
4252                         {
4253                                 if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
4254                                 {
4255                                         _TokenEditPresenter* pTokenEditPresenter = dynamic_cast < _TokenEditPresenter* >(this);
4256                                         if (pTokenEditPresenter)
4257                                         {
4258                                                 if (pTokenEditPresenter->GetSelectedTokenIndex() != -1)
4259                                                 {
4260                                                         return true;
4261                                                 }
4262                                         }
4263                                 }
4264                                 SetBlockRangeWithShiftArrowkey(keyCode);
4265                                 return true;
4266                         }
4267                         else
4268                         {
4269                                 return false;
4270                         }
4271                 }
4272                 else
4273                 {
4274                         if (__pCopyPasteManager->IsCopyPasteSingleHandleExist())
4275                         {
4276                                 InitializeCopyPasteManager();
4277                                 SetBlockRangeWithShiftArrowkey(keyCode);
4278                                 return true;
4279                         }
4280                 }
4281
4282                 switch (keyCode)
4283                 {
4284                         case _KEY_LEFT:
4285                                 __pCopyPasteManager->MoveHandler(_EditCopyPasteManager::HANDLER_MOVE_TYPE_LEFT);
4286                                 break;
4287                         case _KEY_UP:
4288                                 __pCopyPasteManager->MoveHandler(_EditCopyPasteManager::HANDLER_MOVE_TYPE_UP);
4289                                 break;
4290                         case _KEY_DOWN:
4291                                 __pCopyPasteManager->MoveHandler(_EditCopyPasteManager::HANDLER_MOVE_TYPE_DOWN);
4292                                 break;
4293                         case _KEY_RIGHT:
4294                                 __pCopyPasteManager->MoveHandler(_EditCopyPasteManager::HANDLER_MOVE_TYPE_RIGHT);
4295                                 break;
4296                         default:
4297                                 return false;
4298                 }
4299                 return true;
4300         }
4301         else if (_KEY_END_BUTTON == keyCode || _KEY_HOME_BUTTON == keyCode)
4302         {
4303                 if (__isCopyPasteManagerExist)
4304                 {
4305                         InitializeCopyPasteManager();
4306                 }
4307
4308                 FinishTextComposition();
4309
4310                 int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
4311                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine);
4312
4313                 if (_KEY_HOME_BUTTON == keyCode)
4314                 {
4315                         if(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
4316                         {
4317                                 if (__cursorPos != 0)
4318                                 {
4319                                         SetCursorPosition(0);
4320                                 }
4321                                 else
4322                                 {
4323                                         return true;
4324                                 }
4325                         }
4326                         else
4327                         {
4328                                 SetCursorPosition(firstTextIndex);
4329                         }
4330                 }
4331                 else if (_KEY_END_BUTTON == keyCode)
4332                 {
4333                         if(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
4334                         {
4335                                 if (__cursorPos != GetTextLength())
4336                                 {
4337                                         SetCursorPosition(GetTextLength());
4338                                 }
4339                                 else
4340                                 {
4341                                         return true;
4342                                 }
4343                         }
4344                         else
4345                         {
4346                                 int totalLine = __pTextObject->GetTotalLineCount();
4347                                 if (curCursorLine < totalLine - 1)
4348                                 {
4349                                         int nextLinefirstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine+1);
4350                                         SetCursorPosition(nextLinefirstTextIndex-1);
4351                                 }
4352                                 else
4353                                 {
4354                                         if (__cursorPos != GetTextLength())
4355                                         {
4356                                                 SetCursorPosition(GetTextLength());
4357                                         }
4358                                         else
4359                                         {
4360                                                 return true;
4361                                         }
4362                                 }
4363                         }
4364                 }
4365                 DrawText();
4366         }
4367         else if (_KEY_ENTER == keyCode || _KEY_NUMPAD_ENTER == keyCode)
4368         {
4369                 if (__isInputConnectionBound != false && __isTextComposing != false)
4370                 {
4371                         return false;
4372                 }
4373                 else
4374                 {
4375                         if (IsKeypadActionEnabled())
4376                         {
4377                                 char enterText[2] = {'\n', };
4378                                 OnTextCommitted(String(enterText));
4379                         }
4380
4381                         return true;
4382                 }
4383         }
4384         else if (_KEY_BACKSPACE == keyCode)
4385         {
4386                 if (__isTextComposing == false)
4387                 {
4388                         if (__isCopyPasteManagerExist)
4389                         {
4390                                 if (IsBlocked())
4391                                 {
4392                                         __pCopyPasteManager->SetTextBlockReleaseFlag(false);
4393                                 }
4394                                 InitializeCopyPasteManager();
4395                         }
4396
4397                         OnSurroundingTextDeleted(-1, 1);
4398                         if (AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT) == true)
4399                         {
4400                                 __pTextObject->Compose();
4401                                 __pEdit->Invalidate();
4402                         }
4403                         ScrollPanelToCursorPosition();
4404                         return true;
4405                 }
4406         }
4407         else if ((keyInfo.GetKeyModifier() & _KEY_LOCK_NUM) && (_KEY_NUMPAD_4 == keyCode || _KEY_NUMPAD_6 == keyCode || _KEY_NUMPAD_8 == keyCode || _KEY_NUMPAD_2 == keyCode))
4408         {
4409                 return false;
4410         }
4411         else if (_KEY_LEFT == keyCode || _KEY_NUMPAD_4 == keyCode)
4412         {
4413                 if (__isCopyPasteManagerExist)
4414                 {
4415                         InitializeCopyPasteManager();
4416                 }
4417
4418                 FinishTextComposition();
4419
4420                 if (__cursorPos != 0)
4421                 {
4422                         int startPosition = -1;
4423                         int endPosition = -1;
4424                         GetTextImageRangeAt(__cursorPos-1, startPosition, endPosition);
4425                         if (endPosition > -1 && startPosition >= 0 && startPosition < __cursorPos-1)
4426                         {
4427                                 SetCursorPosition(startPosition);
4428                         }
4429                         else
4430                         {
4431                                 SetCursorPosition(__cursorPos-1);
4432                         }
4433
4434                         if (__pParentPanel)
4435                         {
4436                                 panelAbsBounds = __pParentPanel->GetAbsoluteBoundsF(true);
4437                                 GetCursorBounds(true, absCursorBounds);
4438
4439                                 if (!panelAbsBounds.Contains(FloatPoint(absCursorBounds.x, absCursorBounds.y + absCursorBounds.height)))
4440                                 {
4441                                         ScrollPanelToCursorPosition();
4442                                 }
4443                         }
4444
4445                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4446                         {
4447                                 DrawText();
4448                         }
4449                         else
4450                         {
4451                                 __pEdit->Invalidate();
4452                         }
4453                 }
4454                 else
4455                 {
4456                         return false;
4457                 }
4458                 return true;
4459         }
4460         else if (_KEY_UP == keyCode || _KEY_NUMPAD_8 == keyCode)
4461         {
4462                 if (__isCopyPasteManagerExist)
4463                 {
4464                         InitializeCopyPasteManager();
4465                 }
4466
4467                 FinishTextComposition();
4468
4469                 if (GetTextLength() == 0)
4470                 {
4471                         return false;
4472                 }
4473
4474                 int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
4475                 if (curCursorLine !=0)
4476                 {
4477                         int offset = __cursorPos - __pTextObject->GetFirstTextIndexAt(curCursorLine);
4478                         int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine-1);
4479                         int newCursorPosition = offset + firstTextIndex;
4480                         int textLength = __pTextObject->GetTextLengthAt(curCursorLine-1);
4481                         if (offset<textLength)
4482                         {
4483                                 int startPosition = -1;
4484                                 int endPosition = -1;
4485                                 GetTextImageRangeAt(newCursorPosition, startPosition, endPosition);
4486                                 if (endPosition > newCursorPosition && startPosition < newCursorPosition)
4487                                 {
4488                                         newCursorPosition = endPosition;
4489                                 }
4490                                 SetCursorPosition(newCursorPosition);
4491                         }
4492                         else
4493                         {
4494                                 wchar_t ch = '\0';
4495                                 __pTextString->GetCharAt(firstTextIndex+textLength - 1, ch);
4496                                 if (ch == L'\n')
4497                                 {
4498                                         SetCursorPosition(firstTextIndex+textLength - 1);
4499                                 }
4500                                 else
4501                                 {
4502                                         SetCursorPosition(firstTextIndex+textLength);
4503                                 }
4504                         }
4505
4506                         if (__pParentPanel)
4507                         {
4508                                 panelAbsBounds = __pParentPanel->GetAbsoluteBoundsF(true);
4509                                 GetCursorBounds(true, absCursorBounds);
4510                                 if (!panelAbsBounds.Contains(FloatPoint(absCursorBounds.x, absCursorBounds.y)))
4511                                 {
4512                                         ScrollPanelToCursorPosition();
4513                                 }
4514                         }
4515                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4516                         {
4517                                 DrawText();
4518                         }
4519                 }
4520                 else
4521                 {
4522                         return false;
4523                 }
4524                 return true;
4525         }
4526         else if (_KEY_DOWN == keyCode || _KEY_NUMPAD_2 == keyCode)
4527         {
4528                 if (__isCopyPasteManagerExist)
4529                 {
4530                         InitializeCopyPasteManager();
4531                 }
4532
4533                 FinishTextComposition();
4534
4535                 int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
4536                 int totalLine = __pTextObject->GetTotalLineCount();
4537                 if (curCursorLine < totalLine - 1)
4538                 {
4539                         int offset = __cursorPos - __pTextObject->GetFirstTextIndexAt(curCursorLine);
4540                         int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine+1);
4541                         int newCursorPosition = offset + firstTextIndex;
4542                         int textLength = __pTextObject->GetTextLengthAt(curCursorLine+1);
4543
4544                         if (offset<textLength)
4545                         {
4546                                 int startPosition = -1;
4547                                 int endPosition = -1;
4548                                 GetTextImageRangeAt(newCursorPosition, startPosition, endPosition);
4549                                 if (endPosition > newCursorPosition  && startPosition < newCursorPosition)
4550                                 {
4551                                         newCursorPosition = endPosition;
4552                                 }
4553                                 SetCursorPosition(newCursorPosition);
4554                         }
4555                         else
4556                         {
4557                                 wchar_t ch = '\0';
4558                                 __pTextString->GetCharAt(firstTextIndex+textLength - 1, ch);
4559                                 if (ch == L'\n')
4560                                 {
4561                                         if (textLength == 0)
4562                                         {
4563                                                 SetCursorPosition(firstTextIndex);
4564                                         }
4565                                         else
4566                                         {
4567                                                 SetCursorPosition(firstTextIndex+textLength - 1);
4568                                         }
4569                                 }
4570                                 else
4571                                 {
4572                                         SetCursorPosition(firstTextIndex+textLength);
4573                                 }
4574                         }
4575
4576                         if (__pParentPanel)
4577                         {
4578                                 panelAbsBounds = __pParentPanel->GetAbsoluteBoundsF(true);
4579                                 GetCursorBounds(true, absCursorBounds);
4580
4581                                 if (!panelAbsBounds.Contains(FloatPoint(absCursorBounds.x, absCursorBounds.y + absCursorBounds.height)))
4582                                 {
4583                                         ScrollPanelToCursorPosition();
4584                                 }
4585                         }
4586                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4587                         {
4588                                 DrawText();
4589                         }
4590                 }
4591                 else
4592                 {
4593                         return false;
4594                 }
4595                 return true;
4596         }
4597         else if (_KEY_RIGHT == keyCode || _KEY_NUMPAD_6 == keyCode)
4598         {
4599                 if (__isCopyPasteManagerExist)
4600                 {
4601                         InitializeCopyPasteManager();
4602                 }
4603
4604                 FinishTextComposition();
4605
4606                 if (__cursorPos == GetTextLength())
4607                 {
4608                         return false;
4609                 }
4610
4611                 if (__cursorPos < GetTextLength())
4612                 {
4613                         int startPosition = -1;
4614                         int endPosition = -1;
4615                         GetTextImageRangeAt(__cursorPos, startPosition, endPosition);
4616
4617                         if (endPosition > __cursorPos+1  && startPosition > -1)
4618                         {
4619                                 SetCursorPosition(endPosition);
4620                         }
4621                         else
4622                         {
4623                                 SetCursorPosition(__cursorPos+1);
4624                         }
4625
4626                         if (__pParentPanel)
4627                         {
4628                                 panelAbsBounds = __pParentPanel->GetAbsoluteBoundsF(true);
4629                                 GetCursorBounds(true, absCursorBounds);
4630
4631                                 if (!panelAbsBounds.Contains(FloatPoint(absCursorBounds.x, absCursorBounds.y + absCursorBounds.height)))
4632                                 {
4633                                         ScrollPanelToCursorPosition();
4634                                 }
4635                         }
4636
4637                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4638                         {
4639                                 DrawText();
4640                         }
4641                         else
4642                         {
4643                                 __pEdit->Invalidate();
4644                         }
4645                 }
4646                 return true;
4647         }
4648         else if (_KEY_DELETE == keyCode)
4649         {
4650                 if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4651                 {
4652                         if (!GetTextLength())
4653                         {
4654                                 return true;
4655                         }
4656                 }
4657
4658                 if (__isCopyPasteManagerExist)
4659                 {
4660                         if (IsBlocked() == true)
4661                         {
4662                                 int start = 0;
4663                                 int end = 0;
4664                                 GetBlockRange(start, end);
4665                                 DeleteText(start, end);
4666                                 ReleaseTextBlock();
4667                         }
4668                         else
4669                         {
4670                                 int cursorPosition = GetCursorPosition();
4671                                 DeleteText(cursorPosition, cursorPosition+1);
4672                         }
4673
4674                         InitializeCopyPasteManager();
4675                 }
4676                 else
4677                 {
4678                         FinishTextComposition();
4679
4680                         int cursorPosition = GetCursorPosition();
4681                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4682                         {
4683                                 DeleteText(cursorPosition, cursorPosition+1);
4684                         }
4685                         else
4686                         {
4687                                 OnSurroundingTextDeleted(0, 1);
4688                         }
4689                 }
4690
4691                 if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4692                 {
4693                         DrawText();
4694                         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
4695                 }
4696                 else
4697                 {
4698                         __pEdit->Invalidate();
4699                 }
4700
4701                 ScrollPanelToCursorPosition();
4702
4703                 return true;
4704         }
4705         else if (_KEY_CLIPBOARD== keyCode)
4706         {
4707                 __pClipboard->ShowPopup(CLIPBOARD_DATA_TYPE_TEXT, *__pEdit, true);
4708                 __clipboardConnected = true;
4709                 return true;
4710         }
4711         else if (__composingTextLength > 0 && GetTextLength() >= __limitLength)
4712         {
4713                 return true;
4714         }
4715         else if (_KEY_TAB == keyCode)
4716         {
4717                 if (__isCopyPasteManagerExist)
4718                 {
4719                         InitializeCopyPasteManager();
4720                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN) == false)
4721                         {
4722                                 DrawText();
4723                         }
4724                         else
4725                         {
4726                                 __pEdit->Invalidate();
4727                         }
4728                 }
4729                 return false;
4730         }
4731
4732         return false;
4733 }
4734
4735 bool
4736 _EditPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
4737 {
4738         _KeyCode keyCode = keyInfo.GetKeyCode();
4739
4740         if (__isUSBKeyboardConnected && (keyCode == _KEY_SHIFT_L || keyCode == _KEY_SHIFT_R))
4741         {
4742                 if (__pCopyPasteManager && __pCopyPasteManager->IsHandlerMovingEnabled())
4743                 {
4744                         int leftHandler = __pCopyPasteManager->GetHandlerCursorPosition(_EditCopyPasteManager::HANDLER_TYPE_LEFT);
4745                         int rightHandler = __pCopyPasteManager->GetHandlerCursorPosition(_EditCopyPasteManager::HANDLER_TYPE_RIGHT);
4746                         if (leftHandler > rightHandler)
4747                         {
4748                                 __pCopyPasteManager->CreateHandle();
4749                         }
4750                         __pCopyPasteManager->SetHandlerMovingEnabled(false);
4751                         __pCopyPasteManager->CreateCopyPastePopup();
4752                         __pCopyPasteManager->Show();
4753                 }
4754                 else if (__textBlockMoving)
4755                 {
4756                         _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
4757                         SysTryReturn(NID_UI_CTRL, pAccessibilityManager, false, E_SYSTEM, "pAccessibilityManager is null");
4758                         if (!pAccessibilityManager->IsActivated())
4759                         {
4760                                 __pCopyPasteManager = new (std::nothrow) _EditCopyPasteManager(*__pEdit);
4761                                 SysTryReturn(NID_UI_CTRL, __pCopyPasteManager != null, true, E_OUT_OF_MEMORY, "Memory allocation failed.");
4762                                 __pCopyPasteManager->AddCopyPasteEventListener(*this);
4763                                 __pCopyPasteManager->CreateCopyPastePopup();
4764                                 __pCopyPasteManager->Show();
4765                                 __isCopyPasteManagerExist = true;
4766                         }
4767                         __textBlockMoving = false;
4768                 }
4769                 return true;
4770         }
4771
4772         return false;
4773 }
4774
4775 void
4776 _EditPresenter::OnClipboardPopupClosed(const ClipboardItem* pClipboardItem)
4777 {
4778         int start = 0;
4779         int end = 0;
4780         int total = 0;
4781         String userString;
4782         String filteredString;
4783
4784         if (!pClipboardItem && IsBlocked())
4785         {
4786                 ReleaseTextBlock();
4787         }
4788
4789         if (__isCopyPasteManagerExist)
4790         {
4791                 if (IsBlocked())
4792                 {
4793                         __pCopyPasteManager->SetTextBlockReleaseFlag(false);
4794                 }
4795                 InitializeCopyPasteManager();
4796         }
4797
4798         SysTryReturnVoidResult(NID_UI_CTRL, pClipboardItem != null, E_SYSTEM, "[E_SYSTEM] Unable to get the clipboarditem instance.");
4799
4800         String* pClipString = dynamic_cast<String*>(pClipboardItem->GetData());
4801         SysTryReturnVoidResult(NID_UI_CTRL, pClipString != null, E_SYSTEM, "[E_SYSTEM] Unable to get the clipboarditem instance.");
4802
4803         String str;
4804         if (pClipboardItem->GetDataType() == CLIPBOARD_DATA_TYPE_HTML)
4805         {
4806                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
4807                 if (pEcoreEvas)
4808                 {
4809                         str = pEcoreEvas->ConvertMarkupToUtf8(*pClipString);
4810                         pClipString = &str;
4811                 }
4812                 if (str.IsEmpty())
4813                 {
4814                         if (IsBlocked())
4815                         {
4816                                 ReleaseTextBlock();
4817                         }
4818                         delete pClipboardItem;
4819                         return;
4820                 }
4821         }
4822
4823         int currentLength = GetTextLength();
4824         String* pSubString = null;
4825         result r = E_SUCCESS;
4826
4827         filteredString = *pClipString;
4828
4829         if (__pTextFilter)
4830         {
4831                 if(__pTextFilter->ValidatePastedText(*pClipString, userString))
4832                 {
4833                         filteredString = userString;
4834                         SysLog(NID_UI_CTRL, "ClipString was changed by User");
4835                 }
4836         }
4837         else if (IsUnsupportedChracterExist(GetKeypadStyle(), *pClipString) == true)
4838         {
4839                 return;
4840         }
4841
4842         if (IsBlocked())
4843         {
4844                 GetBlockRange(start, end);
4845                 total = currentLength - (end - start) + filteredString.GetLength();
4846                 if (total > __limitLength)
4847                 {
4848                         DeleteText(start, end);
4849                         ReleaseTextBlock();
4850                         pSubString = new String(__limitLength - currentLength + (end - start));
4851                         SysTryCatch(NID_UI_CTRL, pSubString, , r = E_OUT_OF_MEMORY, "Memory allocation failed.");
4852
4853                         filteredString.SubString(0, __limitLength - currentLength + (end - start), *pSubString);
4854                         r = InsertTextAt(__cursorPos, pSubString->GetPointer());
4855                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4856                         delete pSubString;
4857                 }
4858                 else
4859                 {
4860                         DeleteText(start, end);
4861                         ReleaseTextBlock();
4862                         r = InsertTextAt(__cursorPos, filteredString.GetPointer());
4863                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4864                 }
4865         }
4866         else if (currentLength + filteredString.GetLength() > __limitLength)
4867         {
4868                 if (__limitLength == currentLength)
4869                 {
4870                         delete pClipboardItem;
4871                         return;
4872                 }
4873                 
4874                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE || __pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
4875                 {
4876                                 int length = filteredString.GetLength();
4877                                 for (int i = length-1; i >= 0; i--)
4878                                 {
4879                                         wchar_t ch;
4880                                         filteredString.GetCharAt(i, ch);
4881                                         if (ch == '\n')
4882                                         {
4883                                                 filteredString.Remove(i, 1);
4884                                         }
4885                                 }
4886                 }
4887                 
4888                 pSubString = new String(__limitLength - currentLength);
4889                 SysTryCatch(NID_UI_CTRL, pSubString, , r = E_OUT_OF_MEMORY, "Memory allocation failed.");
4890
4891                 filteredString.SubString(0, __limitLength - currentLength, *pSubString);
4892                 r = InsertTextAt(__cursorPos, pSubString->GetPointer());
4893                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4894                 delete pSubString;
4895         }
4896         else
4897         {
4898                 r = InsertTextAt(__cursorPos, filteredString.GetPointer());
4899                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4900         }
4901
4902         ScrollPanelToCursorPosition();
4903
4904         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
4905
4906         __pEdit->Invalidate();
4907
4908         delete pClipboardItem;
4909
4910         return;
4911
4912 CATCH:
4913         delete pClipboardItem;
4914         delete pSubString;
4915         return;
4916 }
4917
4918 bool
4919 _EditPresenter::OnLongPressGestureDetected(void)
4920 {
4921         SysLog(NID_UI_CTRL, "OnLongPressGestureDetected");
4922
4923         if (__isClearIconPressed)
4924         {
4925                 return true;
4926         }
4927
4928         __isTouchPressed = false;
4929
4930         _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
4931         SysTryReturn(NID_UI_CTRL, pAccessibilityManager, false, E_SYSTEM, "pAccessibilityManager is null");
4932         if (pAccessibilityManager->IsActivated())
4933         {
4934                 SysLog(NID_UI_CTRL, "Copy&Paste is not created (ScreenReader is activated)");
4935                 return false;
4936         }
4937
4938         int rowIndex = -1;
4939         int columnIndex = -1;
4940         int cursorPos = -1;
4941
4942         if (__isCopyPasteManagerExist)
4943         {
4944
4945 #if EDIT_DRAG_AND_DROP_ENABLED
4946                 if (IsBlocked())
4947                 {
4948                         int start = -1;
4949                         int end = -1;
4950                         GetBlockRange(start, end);
4951                         __dragAndDropString = GetText(start, end-1);
4952                         _DragAndDropItem* pDragAndDropItem = _DragAndDropItem::CreateInstanceN(_DRAG_AND_DROP_TYPE_TEXT, __dragAndDropString);
4953                         SysTryReturn(NID_UI_CTRL, pDragAndDropItem, false, E_OUT_OF_MEMORY, "Memory allocation failed.");
4954
4955                         cursorPos = GetCursorPositionAt(__pressedPoint, rowIndex, columnIndex);
4956                         if (cursorPos != -1)
4957                         {
4958                                 SetCursorPosition(cursorPos);
4959                         }
4960                         else
4961                         {
4962                                 cursorPos = GetTextLength();
4963                                 SetCursorPosition(cursorPos);
4964                         }
4965
4966                         __pEdit->DragAndDropBegin(*pDragAndDropItem);
4967                         delete pDragAndDropItem;
4968
4969                         __dragAndDropStarted = true;
4970                         InitializeCopyPasteManager();
4971                 }
4972                 else
4973 #endif
4974                 if (!IsBlocked())
4975                 {
4976                         cursorPos = GetCursorPositionAt(__pressedPoint, rowIndex, columnIndex);
4977                         if (cursorPos != -1)
4978                         {
4979                                 SetCursorPosition(cursorPos);
4980                         }
4981                         else
4982                         {
4983                                 return true;
4984                         }
4985                         __pCopyPasteManager->CreateCopyPasteMagnifier();
4986                         __pCopyPasteManager->Show();
4987                         __isTouchLongPressed = true;
4988                         __needToCreateCopyPastePopup = true;
4989                 }
4990                 return true;
4991         }
4992         else if (IsCurrentFocused() == false)
4993         {
4994                 if (IsViewModeEnabled())
4995                 {
4996                         __pEdit->SetFocused();
4997                 }
4998                 else
4999                 {
5000                         return true;
5001                 }
5002         }
5003
5004         FloatRectangle cursorBounds;
5005         InitializeCopyPasteManager();
5006         if (IsClipped() || GetTextLength())
5007         {
5008                 if (IsClipped() && !GetTextLength() && (__pEdit->IsViewModeEnabled()))
5009                 {
5010                         return true;
5011                 }
5012
5013                 if (!IsClipped() && (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD))
5014                 {
5015                         return true;
5016                 }
5017
5018                 FinishTextComposition();
5019
5020                 if (__pPasswordTimer)
5021                 {
5022                         ChangePasswordToEchoCharacter(__pTextBuffer, __echoChar);
5023                         StopPasswordTimer();
5024                 }
5025
5026                 cursorPos = GetCursorPositionAt(__pressedPoint, rowIndex, columnIndex);
5027                 if (cursorPos != -1)
5028                 {
5029                         SetCursorPosition(cursorPos);
5030                 }
5031                 else
5032                 {
5033                         cursorPos = GetTextLength();
5034                         SetCursorPosition(cursorPos);
5035                 }
5036                 ScrollPanelToCursorPosition();
5037                 GetCursorBounds(true, cursorBounds);
5038
5039                 __pCopyPasteManager = new (std::nothrow) _EditCopyPasteManager(*__pEdit);
5040                 SysTryReturn(NID_UI_CTRL, __pCopyPasteManager != null, false, E_SYSTEM, "Unable to create _EditCopyPasteManager instance.");
5041                 __pCopyPasteManager->AddCopyPasteEventListener(*this);
5042                 __pCopyPasteManager->Show();
5043                 __isCopyPasteManagerExist = true;
5044                 __isTouchLongPressed = true;
5045                 __needToCreateCopyPastePopup = true;
5046
5047         }
5048
5049         return true;
5050 }
5051
5052 bool
5053 _EditPresenter::OnTapGestureDetected(void)
5054 {
5055         SysLog(NID_UI_CTRL, "OnTapGestureDetected");
5056
5057         _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
5058         SysTryReturn(NID_UI_CTRL, pAccessibilityManager, false, E_SYSTEM, "pAccessibilityManager is null");
5059         if (pAccessibilityManager->IsActivated())
5060         {
5061                 SysLog(NID_UI_CTRL, "Copy&Paste is not created (ScreenReader is activated)");
5062                 return false;
5063         }
5064
5065         if (IsCurrentFocused() == false)
5066         {
5067                 return true;
5068         }
5069
5070         if (!__isUSBKeyboardConnected)
5071         {
5072                 if (__isKeypadShowing)
5073                         return true;
5074         }
5075
5076         __isTouchPressed = false;
5077         InitializeCopyPasteManager();
5078
5079         if (GetTextLength() > 0)
5080         {
5081                 FloatRectangle cursorBounds;
5082                 int start = -1;
5083                 int end = -1;
5084                 int cursorPos = GetCursorPositionAt(__pressedPoint);
5085
5086                 if (cursorPos == -1)
5087                 {
5088                         cursorPos = GetTextLength();
5089                 }
5090                 else
5091                 {
5092                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(cursorPos);
5093                         int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine);
5094                         if (cursorPos != 0 && cursorPos == firstTextIndex && __rowCursorIndex != curCursorLine)
5095                         {
5096                                 cursorPos--;
5097                         }
5098                 }
5099
5100                 FinishTextComposition();
5101
5102                 GetWordPosition(cursorPos, start, end);
5103                 SetBlockRange(start, end);
5104                 ScrollPanelToCursorPosition();
5105                 GetCursorBounds(true, cursorBounds);
5106
5107                 __pCopyPasteManager = new (std::nothrow) _EditCopyPasteManager(*__pEdit);
5108                 SysTryReturn(NID_UI_CTRL, __pCopyPasteManager != null, false, E_SYSTEM, "Unable to create _EditCopyPasteManager instance.");
5109                 __pCopyPasteManager->AddCopyPasteEventListener(*this);
5110                 __pCopyPasteManager->Show();
5111                 __isCopyPasteManagerExist = true;
5112                 __needToCreateCopyPastePopup = true;
5113
5114                 __pEdit->Draw();
5115         }
5116
5117         return true;
5118 }
5119
5120 HorizontalAlignment
5121 _EditPresenter::GetTextAlignment(void) const
5122 {
5123         return __horizontalAlignment;
5124 }
5125
5126 int
5127 _EditPresenter::GetLineSpacing(void) const
5128 {
5129         int linePixelGap = -1;
5130
5131         linePixelGap = __pTextObject->GetLineSpace();
5132
5133         return linePixelGap;
5134 }
5135
5136 float
5137 _EditPresenter::GetLineSpacingF(void) const
5138 {
5139         float linePixelGap = -1.0;
5140
5141         linePixelGap = __pTextObject->GetLineSpaceF();
5142
5143         return linePixelGap;
5144 }
5145
5146 void
5147 _EditPresenter::GetBlockRange(int& start, int& end) const
5148 {
5149         if (__isTextBlocked == false || __cursorPos == __blockStartPos)
5150         {
5151                 return;
5152         }
5153
5154         if (__cursorPos > __blockStartPos)
5155         {
5156                 start = __blockStartPos;
5157                 end = __cursorPos;
5158         }
5159         else
5160         {
5161                 start = __cursorPos;
5162                 end = __blockStartPos;
5163         }
5164
5165         return;
5166 }
5167
5168 result
5169 _EditPresenter::SetBlockRange(int start, int end)
5170 {
5171         result r = E_SUCCESS;
5172
5173         r = SetCursorPosition(start);
5174         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5175
5176         r = BeginTextBlock();
5177         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5178
5179         r = SetCursorPosition(end);
5180         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5181
5182         return r;
5183 }
5184
5185 result
5186 _EditPresenter::SetBlockRange(int start, int end, int leftRowIndex, int leftColumnIndex, int rightRowIndex, int rightColumnIndex)
5187 {
5188         result r = E_SUCCESS;
5189
5190         if (leftRowIndex == -1 && leftColumnIndex == -1)
5191         {
5192                 r = SetCursorPosition(start);
5193         }
5194         else
5195         {
5196                 r = SetCursorPosition(start, leftRowIndex, leftColumnIndex);
5197         }
5198         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5199
5200         r = BeginTextBlock();
5201         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5202
5203         if (rightRowIndex == -1 && rightColumnIndex == -1)
5204         {
5205                 r = SetCursorPosition(end);
5206         }
5207         else
5208         {
5209                 r = SetCursorPosition(end, rightRowIndex, rightColumnIndex);
5210         }
5211         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5212
5213         return r;
5214 }
5215
5216 result
5217 _EditPresenter::BeginTextBlock(void)
5218 {
5219         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5220                 return E_SYSTEM;
5221
5222         __isTextBlocked = true;
5223         __blockStartPos = __cursorPos;
5224
5225         return E_SUCCESS;
5226 }
5227
5228 result
5229 _EditPresenter::ReleaseTextBlock(void)
5230 {
5231         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5232                 return E_SYSTEM;
5233
5234
5235         if (__isTextBlocked == false)
5236         {
5237                 return E_SYSTEM;
5238         }
5239
5240         __isTextBlocked = false;
5241
5242         return E_SUCCESS;
5243 }
5244
5245 bool
5246 _EditPresenter::IsBlocked(void) const
5247 {
5248         return __isTextBlocked;
5249 }
5250
5251 result
5252 _EditPresenter::CopyText(void)
5253 {
5254         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5255                 return E_SYSTEM;
5256
5257         result r = E_SUCCESS;
5258
5259         _Clipboard* pClipBoard = _Clipboard::GetInstance();
5260         SysTryReturnResult(NID_UI_CTRL, pClipBoard != null, E_SYSTEM, "Unable to get the clipboard instance.");
5261
5262         int start = 0;
5263         int end = 0;
5264         GetBlockRange(start, end);
5265
5266         String blockString(GetText(start, end - 1));
5267
5268         _ClipboardItem* pClipboardItem = _ClipboardItem::CreateInstanceN(CLIPBOARD_DATA_TYPE_TEXT, blockString);
5269         SysTryReturnResult(NID_UI_CTRL, pClipboardItem != null, E_SYSTEM, "Unable to get the clipboarditem instance.");
5270
5271         r = pClipBoard->CopyItem(*pClipboardItem);
5272
5273         delete pClipboardItem;
5274
5275         _Text::TextElement* pStartTextElement = __pTextObject->GetElementAtTextIndex(start);
5276         _Text::TextElement* pEndTextElement = __pTextObject->GetElementAtTextIndex(end-1);
5277
5278         if (pStartTextElement == null || pEndTextElement == null)
5279         {
5280                 return r;
5281         }
5282
5283         const int startIndex = __pTextObject->GetElementIndexOf(*pStartTextElement);
5284         const int endIndex = __pTextObject->GetElementIndexOf(*pEndTextElement);
5285
5286         for (int index = startIndex; index <= endIndex; index++)
5287         {
5288                 _Text::TextElement* pTextElement = __pTextObject->GetElementAtElementIndex(index);
5289                 TextElementType objectType = pTextElement->GetType();
5290                 if (objectType != TEXT_ELEMENT_TYPE_IMAGE)
5291                 {
5292                         continue;
5293                 }
5294                 TextImage* pImageText = null;
5295                 pImageText = dynamic_cast < TextImage* >(pTextElement);
5296                 if (pImageText == null)
5297                 {
5298                         continue;
5299                 }
5300                 const Bitmap * pImage = pImageText->GetBitmap();
5301                 SysTryReturnResult(NID_UI_CTRL, pImage != null, E_SYSTEM, "Unable to get the bitmap from textobject.");
5302
5303                 _ClipboardItem* pClipboardImageItem = _ClipboardItem::CreateInstanceN(CLIPBOARD_DATA_TYPE_IMAGE, *pImage);
5304                 SysTryReturnResult(NID_UI_CTRL, pClipboardImageItem != null, E_SYSTEM, "Unable to get the clipboardImageitem instance.");
5305
5306                 r = pClipBoard->CopyItem(*pClipboardImageItem);
5307
5308                 delete pClipboardImageItem;
5309         }
5310
5311         return r;
5312 }
5313
5314 result
5315 _EditPresenter::CutText(void)
5316 {
5317         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5318                 return E_SYSTEM;
5319
5320         result r = E_SUCCESS;
5321
5322         r = CopyText();
5323         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5324
5325         int start = 0;
5326         int end = 0;
5327         GetBlockRange(start, end);
5328         DeleteText(start, end);
5329         ReleaseTextBlock();
5330
5331         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
5332
5333         return r;
5334 }
5335
5336 result
5337 _EditPresenter::PasteText(void)
5338 {
5339         result r = E_SUCCESS;
5340         int currentLength = GetTextLength();
5341         String* pSubString = null;
5342         int start = 0;
5343         int end = 0;
5344         int total = 0;
5345         String userString;
5346         String filteredString;
5347         String str;
5348
5349         _Clipboard* pClipBoard = _Clipboard::GetInstance();
5350         SysTryReturnResult(NID_UI_CTRL, pClipBoard != null, E_SYSTEM, "Unable to get the clipboard instance.");
5351
5352         const _ClipboardItem* pClipboardItem = pClipBoard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT|CLIPBOARD_DATA_TYPE_AUDIO | CLIPBOARD_DATA_TYPE_VIDEO|CLIPBOARD_DATA_TYPE_HTML);
5353         SysTryReturnResult(NID_UI_CTRL, pClipboardItem != null, E_SYSTEM, "Unable to get the clipboarditem instance.");
5354
5355         const String* pClipString = dynamic_cast<const String*>(pClipboardItem->GetData());
5356         SysTryCatch(NID_UI_CTRL, pClipString, r = E_SYSTEM, E_SYSTEM, "Unable to get the clipboarditem instance.");
5357
5358         if (pClipboardItem->GetDataType() == CLIPBOARD_DATA_TYPE_HTML)
5359         {
5360                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5361                 if (pEcoreEvas)
5362                 {
5363                         str = pEcoreEvas->ConvertMarkupToUtf8(*pClipString);
5364                         pClipString = &str;
5365                 }
5366                 if (str.IsEmpty())
5367                 {
5368                         delete pClipboardItem;
5369                         return r;
5370                 }
5371         }
5372
5373         filteredString = *pClipString;
5374
5375         if (__pTextFilter)
5376         {
5377                 if(__pTextFilter->ValidatePastedText(*pClipString, userString))
5378                 {
5379                         filteredString = userString;
5380                         SysLog(NID_UI_CTRL, "ClipString was changed by User");
5381                 }
5382         }
5383         else if (IsUnsupportedChracterExist(GetKeypadStyle(), *pClipString) == true)
5384         {
5385                 return E_SYSTEM;
5386         }
5387
5388         if (IsBlocked())
5389         {
5390                 GetBlockRange(start, end);
5391                 total = currentLength - (end - start) + filteredString.GetLength();
5392                 if (total > __limitLength)
5393                 {
5394                         DeleteText(start, end);
5395                         ReleaseTextBlock();
5396                         pSubString = new String(__limitLength - currentLength + (end - start));
5397                         SysTryCatch(NID_UI_CTRL, pSubString, , r = E_OUT_OF_MEMORY, "Memory allocation failed.");
5398
5399                         filteredString.SubString(0, __limitLength - currentLength + (end - start), *pSubString);
5400                         r = InsertTextAt(__cursorPos, pSubString->GetPointer());
5401                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5402                         delete pSubString;
5403                 }
5404                 else
5405                 {
5406                         DeleteText(start, end);
5407                         ReleaseTextBlock();
5408                         r = InsertTextAt(__cursorPos, filteredString.GetPointer());
5409                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5410                 }
5411         }
5412         else if (currentLength + filteredString.GetLength() > __limitLength)
5413         {
5414                 if (__limitLength == currentLength)
5415                 {
5416                         delete pClipboardItem;
5417                         return E_SUCCESS;
5418                 }
5419                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE || __pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
5420                 {
5421                                 int length = filteredString.GetLength();
5422                                 for (int i = length-1; i >= 0; i--)
5423                                 {
5424                                         wchar_t ch;
5425                                         filteredString.GetCharAt(i, ch);
5426                                         if (ch == '\n')
5427                                         {
5428                                                 filteredString.Remove(i, 1);
5429                                         }
5430                                 }
5431                 }
5432                 pSubString = new String(__limitLength - currentLength);
5433                 SysTryCatch(NID_UI_CTRL, pSubString, , r = E_OUT_OF_MEMORY, "Memory allocation failed.");
5434
5435                 filteredString.SubString(0, __limitLength - currentLength, *pSubString);
5436                 r = InsertTextAt(__cursorPos, pSubString->GetPointer());
5437                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5438                 delete pSubString;
5439         }
5440         else
5441         {
5442                 r = InsertTextAt(__cursorPos, filteredString.GetPointer());
5443                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5444         }
5445
5446         delete pClipboardItem;
5447
5448         ReplaceTextIntoPasswordHyphenString();
5449         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5450         {
5451                 __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), 0);
5452         }
5453
5454         ScrollPanelToCursorPosition();
5455
5456         __pEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
5457
5458         return r;
5459
5460 CATCH:
5461         delete pClipboardItem;
5462         delete pSubString;
5463         return r;
5464 }
5465
5466 result
5467 _EditPresenter::RemoveTextBlock(void)
5468 {
5469         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5470                 return E_SYSTEM;
5471
5472
5473         if (!__isTextBlocked)
5474         {
5475                 return E_OBJ_NOT_FOUND;
5476         }
5477
5478         int start = 0;
5479         int end = 0;
5480
5481         GetBlockRange(start, end);
5482         if (start == end)
5483         {
5484                 return E_OBJ_NOT_FOUND;
5485         }
5486
5487         result r = DeleteText(start, end);
5488         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5489
5490         __isTextBlocked = false;
5491
5492         InitializeCopyPasteManager();
5493
5494         return r;
5495 }
5496
5497 bool
5498 _EditPresenter::IsClipped(void) const
5499 {
5500         String str;
5501         _Clipboard* pClipBoard = _Clipboard::GetInstance();
5502         SysTryReturn(NID_UI_CTRL, pClipBoard != null, false, E_SYSTEM, "Unable to get the clipboard instance.");
5503
5504         const _ClipboardItem* pClipboardItem = pClipBoard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT|CLIPBOARD_DATA_TYPE_AUDIO | CLIPBOARD_DATA_TYPE_VIDEO|CLIPBOARD_DATA_TYPE_HTML);
5505         if (pClipboardItem == null)
5506         {
5507                 SetLastResult(E_SUCCESS);
5508                 return false;
5509         }
5510
5511         const String* pClipString = dynamic_cast<const String*>(pClipboardItem->GetData());
5512         SysTryCatch(NID_UI_CTRL, pClipString, , GetLastResult(), "Unable to get the clipboarditem data.");
5513
5514         if (pClipboardItem->GetDataType() == CLIPBOARD_DATA_TYPE_HTML)
5515         {
5516                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
5517                 if (pEcoreEvas)
5518                 {
5519                         str = pEcoreEvas->ConvertMarkupToUtf8(*pClipString);
5520                         pClipString = &str;
5521                 }
5522                 if (str.IsEmpty())
5523                 {
5524                         delete pClipboardItem;
5525                         return false;
5526                 }
5527         }
5528
5529         delete pClipboardItem;
5530         return true;
5531
5532 CATCH:
5533         delete pClipboardItem;
5534         return false;
5535 }
5536
5537 result
5538 _EditPresenter::SetTextAlignment(HorizontalAlignment alignment)
5539 {
5540         result r = E_SUCCESS;
5541
5542         int textAlign = TEXT_OBJECT_ALIGNMENT_LEFT;
5543
5544         if (alignment == ALIGNMENT_CENTER)
5545         {
5546                 textAlign = TEXT_OBJECT_ALIGNMENT_CENTER;
5547         }
5548         else if (alignment == ALIGNMENT_RIGHT)
5549         {
5550                 textAlign = TEXT_OBJECT_ALIGNMENT_RIGHT;
5551         }
5552
5553         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
5554         {
5555                 r = __pTextObject->SetAlignment(textAlign | TEXT_OBJECT_ALIGNMENT_MIDDLE);
5556         }
5557         else
5558         {
5559                 r = __pTextObject->SetAlignment(textAlign | TEXT_OBJECT_ALIGNMENT_TOP);
5560         }
5561         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Unable to set text alignment.");
5562         __horizontalAlignment = alignment;
5563
5564         return r;
5565 }
5566
5567 result
5568 _EditPresenter::SetLineSpacing(int linePixelGap)
5569 {
5570         result r = E_SUCCESS;
5571
5572         __pTextObject->SetLineSpace(linePixelGap);
5573
5574         return r;
5575 }
5576
5577 result
5578 _EditPresenter::SetLineSpacing(float linePixelGap)
5579 {
5580         result r = E_SUCCESS;
5581
5582         __pTextObject->SetLineSpace(linePixelGap);
5583
5584         return r;
5585 }
5586
5587 String
5588 _EditPresenter::GetText(int start, int end) const
5589 {
5590         String tempString;
5591
5592         if (start != 0 && end != -1)
5593         {
5594                 SysTryReturn(NID_UI_CTRL, (start <= end), tempString, E_SYSTEM, "[E_SYSTEM] The invalid argument(start = %d, end = %d) is given.", start, end);
5595                 int textLength = GetTextLength();
5596                 SysTryReturn(NID_UI_CTRL, (start < textLength && end < textLength), tempString, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The invalid argument(start = %d, end = %d) is given.", start, end);
5597         }
5598
5599         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
5600         {
5601                 int length = end - start + 1;
5602            __pTextString->SubString(start, length, tempString);
5603
5604            return tempString;
5605         }
5606
5607         String resultString;
5608         String elementString;
5609         const int textElementCount = __pTextObject->GetElementCount();
5610         _Text::TextElement* pTextElement = __pTextObject->GetElementAtTextIndex(start);
5611
5612         if (pTextElement == null)
5613         {
5614                 return resultString;
5615         }
5616         const int startIndex = __pTextObject->GetElementIndexOf(*pTextElement);
5617
5618         for (int index = startIndex; index < textElementCount; index++)
5619         {
5620                 _Text::TextElement* pTextElement = __pTextObject->GetElementAtElementIndex(index);
5621                 TextSimple* pSimpleText = null;
5622                 if (pTextElement == null)
5623                 {
5624                         break;
5625                 }
5626
5627                 TextElementType objectType = pTextElement->GetType();
5628                 if (objectType == TEXT_ELEMENT_TYPE_TEXT || objectType == TEXT_ELEMENT_TYPE_CUTLINK)
5629                 {
5630                         pSimpleText = dynamic_cast < TextSimple* >(pTextElement);
5631                         if (pSimpleText == null)
5632                         {
5633                                 continue;
5634                         }
5635
5636                 }
5637                 else
5638                 {
5639                         continue;
5640                 }
5641
5642                 int elementOffset = static_cast < int >(pTextElement->GetValue(SET_TEXT_OFFSET));
5643                 int elementLength = pTextElement->GetTextLength();
5644
5645                 if (objectType == TEXT_ELEMENT_TYPE_CUTLINK)
5646                 {
5647                         elementOffset = GetLinkElementOffsetInTextBuffer(index);
5648                         if (elementOffset < 0)
5649                         {
5650                                 continue;
5651                         }
5652                 }
5653
5654                 if (end < elementOffset)
5655                 {
5656                         break;
5657                 }
5658                 if (start >= elementOffset + elementLength)
5659                 {
5660                         continue;
5661                 }
5662
5663                 if (elementLength == 0)
5664                 {
5665                         continue;
5666                 }
5667                 elementString.Clear();
5668                 elementString.Append(pSimpleText->GetText());
5669                 elementString.SetLength(elementLength);
5670                 if (end < elementOffset + elementLength - 1)
5671                 {
5672                         int removingStartIndex = end + 1;
5673                         elementString.Remove(removingStartIndex - elementOffset, elementOffset + elementLength - removingStartIndex);
5674                 }
5675                 if (start > elementOffset)
5676                 {
5677                         elementString.Remove(0, start - elementOffset);
5678                 }
5679                 resultString.Append(elementString);
5680         }
5681
5682         return resultString;
5683 }
5684
5685 String
5686 _EditPresenter::GetText(void) const
5687 {
5688         return GetText(0, GetTextLength()-1);
5689 }
5690
5691 result
5692 _EditPresenter::SetText(const String& text)
5693 {
5694         result r = E_SUCCESS;
5695
5696         InitializeCopyPasteManager();
5697
5698         int length = text.GetLength();
5699
5700         if (__pEdit->IsViewModeEnabled())
5701         {
5702                 if (__limitLength <= length)
5703                 {
5704                         String tempString = GetText();
5705                         SetTextLimitLength(length * 2);
5706                 }
5707         }
5708         else
5709         {
5710                 SysTryReturnResult(NID_UI_CTRL, length <= __limitLength, E_INVALID_ARG, "The Invalid argument is given.");
5711         }
5712
5713         FinishTextComposition();
5714
5715         __pTextString->Clear();
5716         __pTextString->Append(text);
5717
5718         wchar_t* tempString = const_cast<wchar_t*>(text.GetPointer());
5719         for (int i = 0; i < length; i++)
5720         {
5721                 __pTextBuffer[i] = tempString[i];
5722         }
5723         __pTextBuffer[length] = 0;
5724
5725         __pTextObject->RemoveAll();
5726         TextSimple* pSimpleText = new (std::nothrow)TextSimple(__pTextBuffer, length,TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, __pFont);
5727         __pTextObject->AppendElement(*pSimpleText);
5728
5729         if (__isInitialized == true)
5730         {
5731                 AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT);
5732         }
5733         __pTextObject->Compose();
5734
5735         ReplaceTextIntoPasswordHyphenString();
5736
5737         __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), 0);
5738
5739         SetCursorPosition(length);
5740
5741         if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
5742         {
5743                 AdjustFlexibleHeight();
5744         }
5745
5746         if (__pEdit->IsViewModeEnabled())
5747         {
5748                 __isCutLinkParserEnabled = true;
5749         }
5750
5751         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
5752
5753         return r;
5754 }
5755
5756 int
5757 _EditPresenter::GetRemainingLength(void) const
5758 {
5759         return __limitLength - __pTextObject->GetTextLength();
5760 }
5761
5762 result
5763 _EditPresenter::SetCursorPosition(int position)
5764 {
5765         result r = E_SUCCESS;
5766         int length = GetTextLength();
5767
5768         SysTryReturnResult(NID_UI_CTRL, -1 < position && position <= length, E_INVALID_ARG, "Invalid argument is given.");
5769
5770         if (__isTouchMoving == false)
5771         {
5772                 __isCursorChanged = true;
5773         }
5774
5775         r = __pTextObject->SetCursorIndex(position);
5776         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to set cursor position");
5777
5778         if (__cursorPos != position)
5779         {
5780                 __pTextObject->ConvertToRowColumn(position, __rowCursorIndex, __columnCursorIndex);
5781                 __cursorPos = position;
5782         }
5783
5784         return r;
5785 }
5786
5787 result
5788 _EditPresenter::SetCursorPosition(int position,int rowIndex, int columnIndex)
5789 {
5790         result r = E_SUCCESS;
5791         int length = GetTextLength();
5792
5793         SysTryReturnResult(NID_UI_CTRL, -1 < position && position <= length, E_INVALID_ARG, "Invalid argument is given.");
5794
5795         if (__isTouchMoving == false)
5796         {
5797                 __isCursorChanged = true;
5798         }
5799
5800         r = __pTextObject->SetCursorIndex(position);
5801         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to set cursor position");
5802
5803         __rowCursorIndex = rowIndex;
5804         __columnCursorIndex = columnIndex;
5805
5806         __cursorPos = position;
5807
5808         return r;
5809 }
5810
5811 int
5812 _EditPresenter::GetCursorPosition(void) const
5813 {
5814         return __cursorPos;
5815 }
5816
5817 int
5818 _EditPresenter::GetTextLength(void) const
5819 {
5820         return __pTextObject->GetTextLength();
5821 }
5822
5823 result
5824 _EditPresenter::InsertTextAt(int index, const String& text)
5825 {
5826         result r = E_SUCCESS;
5827
5828         int currentLength = GetTextLength();
5829         int length = text.GetLength();
5830         int totalLength = currentLength + length;
5831         String insertText = text;
5832         int i = 0;
5833
5834         SysTryReturnResult(NID_UI_CTRL, index >= 0 && index <= currentLength, E_OUT_OF_RANGE, "The Invalid argument is given.");
5835
5836         if (__pEdit->IsViewModeEnabled())
5837         {
5838                 if (__limitLength <= totalLength)
5839                 {
5840                         String tempString = GetText();
5841                         SetTextLimitLength(totalLength * 2);
5842                         SetText(tempString);
5843                 }
5844         }
5845         else
5846         {
5847                 SysTryReturnResult(NID_UI_CTRL, totalLength <= __limitLength, E_MAX_EXCEEDED, "The Invalid argument is given.");
5848         }
5849
5850         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE || __pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
5851         {
5852                 while (insertText.Contains(String(L"\n")))
5853                 {
5854                         for (i = 0; i < length; i++)
5855                         {
5856                                 wchar_t ch;
5857                                 insertText.GetCharAt(i, ch);
5858                                 if (ch == '\n')
5859                                 {
5860                                         insertText.Remove(i, 1);
5861                                         length = insertText.GetLength();
5862
5863                                         if (length == 0)
5864                                         {
5865                                                 return E_SUCCESS;
5866                                         }
5867                                         break;
5868                                 }
5869                         }
5870                 }
5871         }
5872
5873
5874         r = __pTextString->Insert(insertText, index);
5875         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5876
5877         wchar_t* pTempString = const_cast<wchar_t*>(insertText.GetPointer());
5878         wchar_t pOriginalString[currentLength - index];
5879
5880         for (int i = 0; i < currentLength - index; i++)
5881         {
5882                 pOriginalString[i] = __pTextBuffer[index + i];
5883         }
5884         pOriginalString[currentLength - index] = 0;
5885
5886         for (int i = 0; i < length; i++)
5887         {
5888                 __pTextBuffer[i + index] = pTempString[i];
5889         }
5890
5891         for (int i = 0; i < currentLength - index; i++)
5892         {
5893                 __pTextBuffer[i + index + length] = pOriginalString[i];
5894         }
5895         __pTextBuffer[totalLength] = 0;
5896
5897         __pTextObject->InputText(index);
5898         __pTextObject->SetRange(index, length);
5899         r = __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), length);
5900         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to set length");
5901
5902         __pTextObject->Compose();
5903
5904         if (__isTextBlocked == true)
5905         {
5906                 DeleteText(__blockStartPos, __cursorPos);
5907                 ReleaseTextBlock();
5908
5909                 SetCursorPosition(__cursorPos + length);
5910         }
5911         else
5912         {
5913                 SetCursorPosition(index + length);
5914         }
5915
5916         if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
5917         {
5918                 AdjustFlexibleHeight();
5919         }
5920
5921         __isCursorChanged = true;
5922
5923         if (__pEdit->IsViewModeEnabled())
5924         {
5925                 __isCutLinkParserEnabled = true;
5926         }
5927
5928         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
5929
5930         return r;
5931 }
5932
5933 result
5934 _EditPresenter::AppendText(const String& text)
5935 {
5936         result r = E_SUCCESS;
5937
5938         int currentLength = GetTextLength();
5939         int length = text.GetLength();
5940         int totalLength = currentLength + length;
5941
5942         if (__pEdit->IsViewModeEnabled())
5943         {
5944                 if (__limitLength <= totalLength)
5945                 {
5946                         String tempString = GetText();
5947                         SetTextLimitLength(totalLength * 2);
5948                         SetText(tempString);
5949                 }
5950         }
5951         else
5952         {
5953                 SysTryReturnResult(NID_UI_CTRL, totalLength <= __limitLength, E_MAX_EXCEEDED, "The Invalid argument is given.");
5954         }
5955
5956         r = __pTextString->Append(text);
5957         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5958
5959         wchar_t* pTempString = const_cast<wchar_t*>(text.GetPointer());
5960
5961         for (int i = 0; i < length; i++)
5962         {
5963                 __pTextBuffer[i + currentLength] = pTempString[i];
5964         }
5965         __pTextBuffer[totalLength] = 0;
5966
5967         __pTextObject->SetRange(currentLength, length);
5968         r = __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), length);
5969         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to set length");
5970
5971         __pTextObject->Compose();
5972
5973         if (!__isTextBlocked)
5974         {
5975                 SetCursorPosition(totalLength);
5976         }
5977
5978         if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
5979         {
5980                 AdjustFlexibleHeight();
5981         }
5982
5983         if (__pEdit->IsViewModeEnabled())
5984         {
5985                 __isCutLinkParserEnabled = true;
5986         }
5987
5988         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
5989
5990         return r;
5991 }
5992
5993 result
5994 _EditPresenter::AppendCharacter(const Character& character)
5995 {
5996         result r = E_SUCCESS;
5997
5998         r = AppendText(character.ToString());
5999
6000         return r;
6001 }
6002
6003 result
6004 _EditPresenter::ClearText(void)
6005 {
6006         InitializeCopyPasteManager();
6007
6008         result r = E_SUCCESS;
6009
6010         FinishTextComposition();
6011
6012         int textLength = GetTextLength();
6013
6014         if (textLength == 0)
6015         {
6016                 return r;
6017         }
6018
6019         r = DeleteText(0, textLength);
6020         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6021
6022         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_CLEAR_ICON);
6023
6024         return r;
6025 }
6026
6027 result
6028 _EditPresenter::DeleteCharacterAt(int index)
6029 {
6030         result r = E_SUCCESS;
6031
6032         int length = -1;
6033         length = GetTextLength();
6034
6035         SysTryReturnResult(NID_UI_CTRL, index >= 0, E_INVALID_ARG, "Specified index is negative.");
6036         SysTryReturnResult(NID_UI_CTRL, index < length, E_OUT_OF_RANGE, "Specified index is outside the range.");
6037
6038         r = DeleteText(index, index+1);
6039         return r;
6040 }
6041
6042 result
6043 _EditPresenter::DeleteText(int startCursorPosition, int endCursorPosition)
6044 {
6045         result r = E_SUCCESS;
6046
6047         int length = GetTextLength();
6048
6049         SysTryReturnResult(NID_UI_CTRL, -1 < startCursorPosition && startCursorPosition < endCursorPosition, E_INVALID_ARG, "Invalid argument is given.");
6050         SysTryReturnResult(NID_UI_CTRL, startCursorPosition < endCursorPosition && endCursorPosition <= length, E_INVALID_ARG, "Invalid argument is given.");
6051
6052         _Text::TextElement* pFirstTextElement = __pTextObject->GetElementAtTextIndex(startCursorPosition);
6053         const TextSimple* pFirstSimpleText = dynamic_cast <const TextSimple*>(pFirstTextElement);
6054         if (pFirstSimpleText != null && pFirstSimpleText->GetBitmap() != null)
6055         {
6056                 if (pFirstSimpleText->GetTextOffset() < startCursorPosition)
6057                 {
6058                         startCursorPosition = pFirstSimpleText->GetTextOffset();
6059                 }
6060         }
6061         _Text::TextElement* pLastTextElement = __pTextObject->GetElementAtTextIndex(endCursorPosition - 1);
6062         const TextSimple* pLastSimpleText = dynamic_cast <const TextSimple*>(pLastTextElement);
6063         if (pLastSimpleText != null && pLastSimpleText->GetBitmap() != null)
6064         {
6065                 if ((pLastSimpleText->GetTextOffset() + pLastSimpleText->GetTextLength()) > endCursorPosition)
6066                 {
6067                         endCursorPosition = pLastSimpleText->GetTextOffset() + pLastSimpleText->GetTextLength();
6068                 }
6069         }
6070
6071         r = __pTextString->Remove(startCursorPosition, endCursorPosition - startCursorPosition);
6072         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6073
6074         int currentLength = __pTextString->GetLength();
6075
6076         for (int i = startCursorPosition; i < length; i++)
6077         {
6078                 if ((i + length - currentLength) >= length)
6079                 {
6080                         break;
6081                 }
6082                 __pTextBuffer[i] = __pTextBuffer[i + (length - currentLength)];
6083         }
6084
6085         for (int i = currentLength; i < length; i++)
6086         {
6087                 __pTextBuffer[i] = 0;
6088         }
6089
6090         AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT);
6091
6092         __pTextObject->RemoveText(startCursorPosition);
6093         __pTextObject->SetRange(startCursorPosition, endCursorPosition - startCursorPosition);
6094         r = __pTextObject->NotifyTextChanged(__pTextBuffer, 0, currentLength, -(endCursorPosition - startCursorPosition));
6095         r = __pTextObject->Compose();
6096
6097         SetCursorPosition(startCursorPosition);
6098
6099         if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
6100         {
6101                 AdjustFlexibleHeight();
6102         }
6103
6104         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
6105
6106         return r;
6107 }
6108
6109 void
6110 _EditPresenter::GetCurrentTextRange(int& start, int& end) const
6111 {
6112         int currentLength = __pTextString->GetLength();
6113
6114         start = __cursorPos;
6115         while (start > 0)
6116         {
6117                 if (__pTextBuffer[--start] == TEXT_OBJ_CHARACTER)
6118                 {
6119                         start++;
6120                         break;
6121                 }
6122         }
6123
6124         end = __cursorPos;
6125         while (end < currentLength && __pTextBuffer[end] != TEXT_OBJ_CHARACTER)
6126         {
6127                 end++;
6128         }
6129
6130         return;
6131 }
6132
6133 int
6134 _EditPresenter::GetTextLimitLength(void) const
6135 {
6136         return __limitLength;
6137 }
6138
6139 result
6140 _EditPresenter::SetTextLimitLength(int limitLength)
6141 {
6142         result r = E_SUCCESS;
6143
6144         SysTryReturnResult(NID_UI_CTRL, (limitLength > 0), E_INVALID_ARG, "The invalid limit length is given.");
6145
6146         String tempString = GetText();
6147
6148         int textLength = tempString.GetLength();
6149         SysTryReturnResult(NID_UI_CTRL, (limitLength >= textLength), E_INVALID_ARG, "The invalid argument is given.");
6150
6151         TextSimple* pSimpleText = null;
6152
6153         if (limitLength == GetTextLimitLength())
6154         {
6155                 return E_SUCCESS;
6156         }
6157
6158         wchar_t* pTempBuffer = new (std::nothrow) wchar_t[limitLength + 1];
6159         SysTryReturnResult(NID_UI_CTRL, pTempBuffer, E_OUT_OF_MEMORY, "Memory allocation failed.");
6160
6161         for (int i = 0; i < textLength; i++)
6162         {
6163                 pTempBuffer[i] = __pTextBuffer[i];
6164         }
6165
6166         for (int i = textLength; i < limitLength; i++)
6167         {
6168                 pTempBuffer[i] = 0;
6169         }
6170
6171         pTempBuffer[limitLength] = '\0';
6172
6173         __pTextString->Clear();
6174         __pTextString->Append(tempString);
6175         if (__pTextBuffer)
6176         {
6177                 delete[] __pTextBuffer;
6178                 __pTextBuffer = null;
6179         }
6180         __pTextBuffer = pTempBuffer;
6181
6182         __pTextObject->RemoveAll();
6183         pSimpleText = new (std::nothrow)TextSimple(__pTextBuffer, textLength, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, __pFont);
6184         SysTryReturnResult(NID_UI_CTRL, pSimpleText, E_OUT_OF_MEMORY, "Memory allocation failed.");
6185
6186         r = __pTextObject->AppendElement(*pSimpleText);
6187         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
6188
6189         SetCursorPosition(textLength);
6190
6191         __limitLength = limitLength;
6192
6193         return r;
6194
6195 CATCH:
6196         delete pSimpleText;
6197         pSimpleText = null;
6198         return r;
6199 }
6200
6201 result
6202 _EditPresenter::InsertCharacterAt(int index, const Character& character)
6203 {
6204         result r = E_SUCCESS;
6205
6206         r = InsertTextAt(index, character.ToString());
6207
6208         return r;
6209 }
6210
6211 result
6212 _EditPresenter::SetModel(const _EditModel& editModel)
6213 {
6214         if (__pEditModel)
6215         {
6216                 delete __pEditModel;
6217                 __pEditModel = null;
6218         }
6219
6220         __pEditModel = const_cast<_EditModel*>(&editModel);
6221
6222         return E_SUCCESS;
6223 }
6224
6225 result
6226 _EditPresenter::SetAutoLinkMask(unsigned long autoLinks)
6227 {
6228         __isCutLinkParserEnabled = true;
6229         return __pEditModel->SetAutoLinkMask(autoLinks);
6230 }
6231
6232 unsigned long
6233 _EditPresenter::GetAutoLinkMask(void) const
6234 {
6235         return __pEditModel->GetAutoLinkMask();
6236 }
6237
6238 bool
6239 _EditPresenter::IsViewModeEnabled(bool internal) const
6240 {
6241         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
6242         {
6243                 return __pEditModel->IsViewModeEnabled();
6244         }
6245         else
6246         {
6247                 if (internal)
6248                 {
6249                         return true;
6250                 }
6251                 else
6252                 {
6253                         return __pEditModel->IsViewModeEnabled();
6254                 }
6255         }
6256 }
6257
6258 result
6259 _EditPresenter::SetViewModeEnabled(bool enable)
6260 {
6261         if (!enable && __pEditModel->IsViewModeEnabled() && IsCurrentFocused() && (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY))
6262         {
6263                 __pEdit->SetFocused(false);
6264         }
6265
6266         int editStyle = __pEdit->GetEditStyle();
6267
6268         if (enable)
6269         {
6270                 editStyle = editStyle | EDIT_STYLE_VIEWER;
6271         }
6272         else
6273         {
6274                 editStyle = editStyle & (~EDIT_STYLE_VIEWER);
6275         }
6276         __pEdit->SetEditStyle(editStyle);
6277
6278         if (enable)
6279         {
6280                 __pEdit->SetCursorPosition(0);
6281
6282                 if (__pInputConnection && __isInputConnectionBound)
6283                 {
6284                         HideKeypad(true);
6285                 }
6286         }
6287
6288         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
6289         {
6290                 __isCursorDisabled = enable;
6291                 __pTextObject->SetCutLinkViewMode(enable);
6292         }
6293
6294         if (__pInputConnection)
6295         {
6296                 if (enable)
6297                 {
6298                         __pInputConnection->SetKeyEventSkipped(true);
6299                 }
6300                 else
6301                 {
6302                         if (IsKeypadEnabled())
6303                         {
6304                                 __pInputConnection->SetKeyEventSkipped(false);
6305                         }
6306                 }
6307         }
6308
6309         return __pEditModel->SetViewModeEnabled(enable);
6310 }
6311
6312 result
6313 _EditPresenter::SetKeypadActionEnabled(bool enable)
6314 {
6315
6316         result r = E_SUCCESS;
6317
6318         r = __pInputConnection->SetInputPanelActionEnabled(enable);
6319
6320         if (r == E_SUCCESS)
6321                 __pEditModel->SetKeypadActionEnabled(enable);
6322
6323         return r;
6324 }
6325
6326 bool
6327 _EditPresenter::IsKeypadActionEnabled(void)
6328 {
6329         bool enable = true;
6330         bool enableIc = true;
6331
6332         enable = __pEditModel->IsKeypadActionEnabled();
6333         enableIc = __pInputConnection->IsInputPanelActionEnabled();
6334
6335         return enable;
6336 }
6337
6338 CoreKeypadAction
6339 _EditPresenter::GetKeypadAction(void) const
6340 {
6341         return __pEditModel->GetKeypadAction();
6342 }
6343
6344 InputPanelAction
6345 _EditPresenter::ConvertKeypadAction(CoreKeypadAction keypadAction)
6346 {
6347         InputPanelAction inputPanelAction = INPUT_PANEL_ACTION_ENTER;
6348
6349         switch (keypadAction)
6350         {
6351         case CORE_KEYPAD_ACTION_ENTER:
6352                 inputPanelAction = INPUT_PANEL_ACTION_ENTER;
6353                 break;
6354         case CORE_KEYPAD_ACTION_GO:
6355                 inputPanelAction = INPUT_PANEL_ACTION_GO;
6356                 break;
6357         case CORE_KEYPAD_ACTION_NEXT:
6358                 inputPanelAction = INPUT_PANEL_ACTION_NEXT;
6359                 break;
6360         case CORE_KEYPAD_ACTION_SEND:
6361                 inputPanelAction = INPUT_PANEL_ACTION_SEND;
6362                 break;
6363         case CORE_KEYPAD_ACTION_SEARCH:
6364                 inputPanelAction = INPUT_PANEL_ACTION_SEARCH;
6365                 break;
6366         case CORE_KEYPAD_ACTION_LOGIN:
6367                 inputPanelAction = INPUT_PANEL_ACTION_LOGIN;
6368                 break;
6369         case CORE_KEYPAD_ACTION_SIGN_IN:
6370                 inputPanelAction = INPUT_PANEL_ACTION_SIGN_IN;
6371                 break;
6372         case CORE_KEYPAD_ACTION_JOIN:
6373                 inputPanelAction = INPUT_PANEL_ACTION_JOIN;
6374                 break;
6375         case CORE_KEYPAD_ACTION_DONE:
6376                 inputPanelAction = INPUT_PANEL_ACTION_DONE;
6377                 break;
6378         default:
6379                 break;
6380         }
6381
6382         return inputPanelAction;
6383 }
6384
6385
6386 result
6387 _EditPresenter::SetKeypadAction(CoreKeypadAction keypadAction)
6388 {
6389         return __pEditModel->SetKeypadAction(keypadAction);
6390 }
6391
6392 void
6393 _EditPresenter::SetKeypadEnabled(bool enable)
6394 {
6395         if (!enable && IsKeypadEnabled())
6396         {
6397                 CheckUSBKeyboardStatus();
6398                 //hide keypad
6399                 if (!__isUSBKeyboardConnected && __isInputConnectionBound)
6400                 {
6401                         HideKeypad(false);
6402                 }
6403         }
6404
6405         __pEditModel->SetKeypadEnabled(enable);
6406
6407         if (__pInputConnection)
6408         {
6409                 if (!enable)
6410                 {
6411                         __pInputConnection->SetKeyEventSkipped(true);
6412                 }
6413                 else
6414                 {
6415                         if (!__pEditModel->IsViewModeEnabled())
6416                         {
6417                                 __pInputConnection->SetKeyEventSkipped(false);
6418                         }
6419                 }
6420         }
6421
6422         return;
6423 }
6424
6425 void
6426 _EditPresenter::SetKeypadEventSkipped(bool skip)
6427 {
6428         if (skip)
6429         {
6430                 __pInputConnection->SetKeyEventSkipped(true);
6431         }
6432         else
6433         {
6434                 if (__pEdit->IsEnabled() && !__pEditModel->IsViewModeEnabled() && IsKeypadEnabled())
6435                 {
6436                         __pInputConnection->SetKeyEventSkipped(false);
6437                 }
6438         }
6439 }
6440
6441 bool
6442 _EditPresenter::IsKeypadEnabled(void)
6443 {
6444         bool enable = true;
6445
6446         if (__pEdit->IsEnabled())
6447         {
6448                 enable = __pEditModel->IsKeypadEnabled();
6449         }
6450         else
6451         {
6452                 enable = false;
6453         }
6454
6455         return enable;
6456 }
6457
6458 result
6459 _EditPresenter::SetCurrentLanguage(LanguageCode languageCode)
6460 {
6461         result r = E_SUCCESS;
6462
6463         if (__pInputConnection && __isInputConnectionBound)
6464         {
6465                 r = __pInputConnection->SetInputPanelLanguage(languageCode);
6466                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6467                 r = __pEditModel->SetInitialKeypadLanguage(LANGUAGE_INVALID);
6468                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6469         }
6470         else
6471         {
6472                 r = __pEditModel->SetInitialKeypadLanguage(languageCode);
6473                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6474         }
6475
6476         r = __pEditModel->SetCurrentLanguage(languageCode);
6477
6478         return r;
6479 }
6480
6481 result
6482 _EditPresenter::GetCurrentLanguage(LanguageCode& language) const
6483 {
6484         result r = E_SUCCESS;
6485         if (__pInputConnection && __isInputConnectionBound)
6486         {
6487                 language = __pInputConnection->GetInputPanelLanguage();
6488                 r = __pEditModel->SetCurrentLanguage(language);
6489                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6490                 return r;
6491         }
6492         return __pEditModel->GetCurrentLanguage(language);
6493 }
6494
6495 void
6496 _EditPresenter::SetLowerCaseModeEnabled(bool enable)
6497 {
6498         __pEditModel->SetLowerCaseModeEnabled(enable);
6499
6500         return;
6501 }
6502
6503 bool
6504 _EditPresenter::IsLowerCaseModeEnabled(void) const
6505 {
6506         return __pEditModel->IsLowerCaseModeEnabled();
6507 }
6508
6509 KeypadStyle
6510 _EditPresenter::GetKeypadStyle(void) const
6511 {
6512         return __pEditModel->GetKeypadStyle();
6513 }
6514
6515 result
6516 _EditPresenter::SetKeypadStyle(KeypadStyle keypadStyle)
6517 {
6518
6519         bool textPredictionEnabled = __pEditModel->IsTextPredictionEnabled();
6520
6521         InputPanelStyle inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;
6522
6523         switch (keypadStyle)
6524         {
6525         case KEYPAD_STYLE_NORMAL:
6526                 if (__isKeypadNormalNumberStyleEnabled)
6527                 {
6528                         inputPanelStyle = INPUT_PANEL_STYLE_NUMBER;
6529                 }
6530                 else
6531                 {
6532                         inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;
6533                 }
6534                 break;
6535         case KEYPAD_STYLE_PASSWORD:
6536                 inputPanelStyle = INPUT_PANEL_STYLE_NORMAL;
6537                 if (__pInputConnection)
6538                 {
6539                         __pInputConnection->SetPasswordMode(true);
6540                 }
6541                 break;
6542         case KEYPAD_STYLE_EMAIL:
6543                 inputPanelStyle = INPUT_PANEL_STYLE_EMAIL;
6544                 break;
6545         case KEYPAD_STYLE_URL:
6546                 inputPanelStyle = INPUT_PANEL_STYLE_URL;
6547                 break;
6548         case KEYPAD_STYLE_NUMBER:
6549                 inputPanelStyle = INPUT_PANEL_STYLE_NUMBER_ONLY;
6550                 textPredictionEnabled = false;
6551                 break;
6552         case KEYPAD_STYLE_PHONE_NUMBER:
6553                 inputPanelStyle = INPUT_PANEL_STYLE_PHONE_NUMBER;
6554                 textPredictionEnabled = false;
6555                 break;
6556         case KEYPAD_STYLE_IP_V4:
6557                 inputPanelStyle = INPUT_PANEL_STYLE_IP;
6558                 textPredictionEnabled = false;
6559                 break;
6560         default:
6561                 break;
6562         }
6563
6564         if (__pInputConnection && __isInputConnectionBound)
6565         {
6566                 __pInputConnection->SetTextPredictionEnabled(textPredictionEnabled);
6567                 __pInputConnection->SetInputPanelStyle(inputPanelStyle);
6568         }
6569
6570         __pEditModel->SetTextPredictionEnabled(textPredictionEnabled);
6571
6572         return __pEditModel->SetKeypadStyle(keypadStyle);
6573 }
6574
6575 result
6576 _EditPresenter::SetKeypadNormalNumberStyle(bool enable)
6577 {
6578         __isKeypadNormalNumberStyleEnabled = enable;
6579         return SetKeypadStyle(__pEditModel->GetKeypadStyle());
6580 }
6581
6582 bool
6583 _EditPresenter::IsTextPredictionEnabled(void) const
6584 {
6585         return __pEditModel->IsTextPredictionEnabled();
6586 }
6587
6588 result
6589 _EditPresenter::SetTextPredictionEnabled(bool enable)
6590 {
6591         KeypadStyle keypadStyle = __pEditModel->GetKeypadStyle();
6592
6593         if (keypadStyle == KEYPAD_STYLE_NUMBER ||keypadStyle == KEYPAD_STYLE_PHONE_NUMBER ||
6594                 keypadStyle == KEYPAD_STYLE_IP_V4)
6595                 return E_UNSUPPORTED_OPERATION;
6596
6597         if (__pInputConnection && __isInputConnectionBound)
6598         {
6599                 __pInputConnection->SetTextPredictionEnabled(enable);
6600         }
6601
6602         return __pEditModel->SetTextPredictionEnabled(enable);
6603 }
6604
6605 result
6606 _EditPresenter::InsertTextAtCursorPosition(const String& text)
6607 {
6608         return InsertTextAt(__cursorPos, text);
6609 }
6610
6611 result
6612 _EditPresenter::InsertTextAt(int position, const String& text, const Bitmap& textImage)
6613 {
6614         result r = E_SUCCESS;
6615
6616         int currentLength = GetTextLength();
6617         int length = text.GetLength();
6618         int totalLength = currentLength + length;
6619
6620         SysTryReturnResult(NID_UI_CTRL, position >= 0 && position <= currentLength, E_OUT_OF_RANGE, "The given position is out-of-range.");
6621
6622         if ((__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE) || (__pEdit->IsViewModeEnabled()))
6623         {
6624                 if (__limitLength <= totalLength)
6625                 {
6626                         String backupString = GetText();
6627                         SetTextLimitLength(totalLength * 2);
6628                         SetText(backupString);
6629                 }
6630         }
6631         else
6632         {
6633                 SysTryReturnResult(NID_UI_CTRL, totalLength <= __limitLength, E_MAX_EXCEEDED, "The text exceeds the limitation length.");
6634         }
6635
6636         FinishTextComposition();
6637
6638         r = __pTextString->Insert(text, position);
6639         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
6640
6641         wchar_t* pInsertString = const_cast<wchar_t*>(text.GetPointer());
6642
6643         if (currentLength > position)
6644         {
6645                 wchar_t pOriginalString[currentLength - position];
6646
6647                 for (int i = 0; i < currentLength - position; i++)
6648                 {
6649                         pOriginalString[i] = __pTextBuffer[position + i];
6650                 }
6651                 pOriginalString[currentLength - position] = 0;
6652
6653                 for (int i = 0; i < length; i++)
6654                 {
6655                         __pTextBuffer[i + position] = pInsertString[i];
6656                 }
6657
6658                 for (int i = 0; i < currentLength - position; i++)
6659                 {
6660                         __pTextBuffer[i + position + length] = pOriginalString[i];
6661                 }
6662         }
6663         else
6664         {
6665                 for (int i = 0; i < length; i++)
6666                 {
6667                         __pTextBuffer[i + position] = pInsertString[i];
6668                 }
6669         }
6670
6671         __pTextBuffer[totalLength] = 0;
6672
6673         TextSimple* pSimpleText = null;
6674         pSimpleText = new (std::nothrow) TextSimple(__pTextBuffer, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, GetFont());
6675         SysTryReturnResult(NID_UI_CTRL, pSimpleText, E_OUT_OF_MEMORY, "Memory allocation failed.");
6676
6677         pSimpleText->ChangeTextOffset(__pTextBuffer, position);
6678         pSimpleText->SetBitmap((Bitmap&)textImage);
6679         __pTextObject->InsertElementAt(position, *pSimpleText);
6680         __pTextObject->ChangeTextOffset(__pTextBuffer, position+pSimpleText->GetTextLength(), pSimpleText->GetTextLength());
6681         __pTextObject->Compose();
6682
6683         if (__isTextBlocked == true)
6684         {
6685                 DeleteText(__blockStartPos, __cursorPos);
6686                 ReleaseTextBlock();
6687
6688                 SetCursorPosition(__cursorPos + length);
6689         }
6690         else
6691         {
6692                 SetCursorPosition(position + length);
6693         }
6694
6695         if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
6696         {
6697                 AdjustFlexibleHeight();
6698         }
6699
6700         __isCursorChanged = true;
6701         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
6702         return r;
6703 }
6704
6705 result
6706 _EditPresenter::DeleteCharacterAtCursorPosition(void)
6707 {
6708         return DeleteCharacterAt(__cursorPos);
6709 }
6710
6711 bool
6712 _EditPresenter::IsFocused(void) const
6713 {
6714         return __pEdit->IsFocused();
6715 }
6716
6717 bool
6718 _EditPresenter::IsInternalFocused(void) const
6719 {
6720         return __pEdit->IsInternalFocused();
6721 }
6722
6723 _VisualElement*
6724 _EditPresenter::GetTextVisualElement(void)
6725 {
6726         return __pTextVisualElement;
6727 }
6728
6729 void
6730 _EditPresenter::SetControlInitialBounds(FloatRectangle initBounds)
6731 {
6732         __initialBounds = initBounds;
6733 }
6734
6735 void
6736 _EditPresenter::SetControlInitialPosition(FloatPoint initPosition)
6737 {
6738         __initialBounds.x = initPosition.x;
6739         __initialBounds.y = initPosition.y;
6740 }
6741
6742 bool
6743 _EditPresenter::IsUpdateInitialBounds(void)
6744 {
6745         return __updateInitialBounds;
6746 }
6747
6748 bool
6749 _EditPresenter::OnFocusGained(void)
6750 {
6751         __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
6752
6753         if (!__pParentForm)
6754         {
6755                 __pParentForm = GetParentForm();
6756
6757                 if (!__pParentForm && __isKeypadCommandButtonVisible)
6758                 {
6759                         __isKeypadCommandButtonVisible = false;
6760                 }
6761         }
6762
6763         if (__isAutoShrinkEnabled)
6764         {
6765                 float flexibleHeight = CalculateFlexibleHeightF();
6766                 FloatRectangle initialRect = GetInitialBoundsF();
6767                 initialRect.height = flexibleHeight;
6768
6769                 SetFlexBounds(initialRect);
6770         }
6771
6772         if (!__pTextVisualElement)
6773         {
6774                 result r = E_SUCCESS;
6775                 __pTextVisualElement = new (std::nothrow) _VisualElement;
6776                 SysTryReturn(NID_UI_CTRL, __pTextVisualElement != null, false, E_OUT_OF_MEMORY, "Memory allocation failed.");
6777
6778                 r = __pTextVisualElement->Construct();
6779                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
6780
6781                 __pTextVisualElement->SetSurfaceOpaque(false);
6782                 __pTextVisualElement->SetImplicitAnimationEnabled(false);
6783
6784                 __pTextVisualElement->SetShowState(true);
6785
6786                 _VisualElement* pEditVisualElement = __pEdit->GetVisualElement();
6787                 SysTryCatch(NID_UI_CTRL, pEditVisualElement, , r = E_SYSTEM, "[E_SYSTEM] Unable to get root visual element.");
6788
6789                 pEditVisualElement->AttachChild(*__pTextVisualElement);
6790                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add child", GetErrorMessage(r));
6791         }
6792
6793         if (__pEdit->GetEnableState() == false)
6794         {
6795                 return false;
6796         }
6797
6798         __isCursorOpaque = true;
6799
6800         if (__isInputConnectionBound == false && __isInitialized)
6801         {
6802                 if (IsViewModeEnabled() == false)
6803                 {
6804                         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
6805                         {
6806                                 ShowKeypad(false);
6807                         }
6808                         else
6809                         {
6810                                 ShowFullscreenKeypad();
6811                         }
6812                 }
6813
6814                 __pEdit->Invalidate();
6815         }
6816
6817         return true;
6818 CATCH:
6819         __pTextVisualElement->Destroy();
6820         __pTextVisualElement = null;
6821
6822         return false;
6823 }
6824
6825 bool
6826 _EditPresenter::OnNotifiedN(IList* pArgs)
6827 {
6828         String showKeypad(L"ShowKeypad");
6829         String showCopyPaste(L"ShowCopyPaste");
6830
6831         String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
6832
6833         if (pType)
6834         {
6835                 if (*pType == showKeypad)
6836                 {
6837                         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
6838                         {
6839                                 ShowKeypad(false);
6840                         }
6841                         else
6842                         {
6843                                 ShowFullscreenKeypad();
6844                         }
6845                 }
6846                 else if (*pType == showCopyPaste)
6847                 {
6848                         if (__pCopyPasteManager)
6849                         {
6850                                 __pCopyPasteManager->CreateHandle();
6851                                 __pCopyPasteManager->DestroyCopyPasteMagnifier();
6852                                 if (__needToCreateCopyPastePopup)
6853                                 {
6854                                         if (__pParentPanel)
6855                                         {
6856                                                 if (!__pParentPanel->IsScrollAnimationRunning())
6857                                                 {
6858                                                         __pCopyPasteManager->CreateCopyPastePopup();
6859                                                         if (__pCopyPasteManager->GetCopyPastePopup())
6860                                                         {
6861                                                                 __needToCreateCopyPastePopup = false;
6862                                                         }
6863                                                 }
6864                                         }
6865                                         else
6866                                         {
6867                                                 __pCopyPasteManager->CreateCopyPastePopup();
6868                                                 if (__pCopyPasteManager->GetCopyPastePopup())
6869                                                 {
6870                                                         __needToCreateCopyPastePopup = false;
6871                                                 }
6872                                         }
6873                                 }
6874                                 __pCopyPasteManager->Show();
6875                         }
6876                 }
6877                 pArgs->RemoveAll(true);
6878                 delete pArgs;
6879
6880                 return true;
6881         }
6882
6883         return false;
6884 }
6885
6886 void
6887 _EditPresenter::OnFrameActivated(const _Frame& source)
6888 {
6889         _ControlManager* pControlManager = _ControlManager::GetInstance();
6890         if (pControlManager)
6891         {
6892                 _Control* pControl = pControlManager->GetFocusControl();
6893                 if (pControl != __pEdit)
6894                 {
6895                         return;
6896                 }
6897         }
6898
6899         if (__isInputConnectionBound == false && __isInitialized)
6900         {
6901                 if (IsViewModeEnabled() == false)
6902                 {
6903                         CheckUSBKeyboardStatus();
6904
6905                         if (__pEdit->GetInputStyle() == INPUT_STYLE_OVERLAY)
6906                         {
6907                                 ShowKeypad(false);
6908                         }
6909                 }
6910         }
6911
6912         return;
6913 }
6914
6915 void
6916 _EditPresenter::OnFrameDeactivated(const _Frame& source)
6917 {
6918         return;
6919 }
6920
6921 void
6922 _EditPresenter::OnFrameMinimized(const _Frame& source)
6923 {
6924         return;
6925 }
6926
6927 void
6928 _EditPresenter::OnFrameRestored(const _Frame& source)
6929 {
6930         return;
6931 }
6932
6933 void
6934 _EditPresenter::ChangeToUnbindState(bool removeFocus)
6935 {
6936         if(__latestBoundedContext != (unsigned int)this)//context is already changed.
6937         {
6938                 __isKeypadHiding = false;
6939         }
6940
6941         if (IsCopyPasteManagerExist())
6942         {
6943                 InitializeCopyPasteManager();
6944         }
6945
6946         if (__isInputConnectionBound)
6947         {
6948                 HideKeypad(removeFocus);
6949
6950                 if (__isClipboardExist)
6951                 {
6952                         if (__pClipboard)
6953                         {
6954                                 __pClipboard->HidePopup();
6955                                 OnClipboardPopupClosed();
6956                         }
6957                 }
6958         }
6959
6960         if (__isKeypadHiding)
6961         {
6962                 if (__pParentForm && !__pParentForm->IsVisible())  //Unbind by Scene Change
6963                 {
6964                         if (__isCopyPasteManagerExist)
6965                         {
6966                                 InitializeCopyPasteManager();
6967                                 __pTextObject->SetBlock(false);
6968                                 __isTextBlocked = false;
6969                         }
6970
6971                         if (__pCommandButton && __isKeypadCommandButtonVisible)
6972                         {
6973                                 SetFooterVisible(true);
6974                                 __pCommandButton->SetVisibleState(false);
6975                                 __pCommandButton->Invalidate();
6976                         }
6977
6978                         __isInputConnectionBound = false;
6979
6980                         AdjustParentPanelHeight(true);
6981                         SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
6982                         __pParentForm->DeflateClientRectHeight(0);
6983
6984                         if (!__pEdit->IsFullScreenKeypadEdit())
6985                         {
6986                                 if (__pParentForm)
6987                                 {
6988                                         __pParentForm->Draw();
6989                                 }
6990                         }
6991
6992                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CLOSED);
6993                         __pEdit->DetachScrollPanelEvent();
6994
6995                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CLOSE);
6996                         __resizedByKeypadHide = true;
6997                         __latestBoundedContext = null;
6998                 }
6999         }
7000
7001         return;
7002 }
7003
7004 bool
7005 _EditPresenter::OnFocusLost(void)
7006 {
7007         if (__dragAndDropStarted)
7008         {
7009                 ResetDragAndDrop();
7010         }
7011
7012         if (!__pEdit->IsDestroyed())
7013         {
7014                 InitializeCopyPasteManager();
7015                 __pEdit->SetTouchPressThreshold(__defaultTouchMoveThreshold);
7016         }
7017
7018         if (__isAutoShrinkEnabled)
7019         {
7020                 FloatRectangle intialWindowBounds = GetInitialBoundsF();
7021                 SetFlexBounds(intialWindowBounds);
7022         }
7023
7024         if (__pTextVisualElement)
7025         {
7026                 __pTextVisualElement->Destroy();
7027                 __pTextVisualElement = null;
7028         }
7029
7030         if (__pEdit == null)
7031         {
7032                 return false;
7033         }
7034
7035         if (__isClipboardExist)
7036         {
7037                 if (__pClipboard)
7038                 {
7039                         __pClipboard->HidePopup();
7040                         OnClipboardPopupClosed();
7041                 }
7042         }
7043
7044         if (__isInputConnectionBound)
7045         {
7046
7047                 if (__pScrollBar && !(__pEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL))
7048                 {
7049                         __pScrollBar->SetScrollVisibility(false);
7050                 }
7051
7052                 __isCursorOpaque = false;
7053                 __isTouchMoving = false;
7054                 __isTouchReleaseSkipped = false;
7055
7056                 HideKeypad();
7057         }
7058
7059         ReplaceTextIntoPasswordHyphenString();
7060
7061         __pEdit->Invalidate();
7062
7063         return true;
7064 }
7065
7066 EditStatus
7067 _EditPresenter::GetCurrentStatus(void)
7068 {
7069         EditStatus editState = EDIT_STATUS_NORMAL;
7070
7071         if (__pEdit->IsEnabled())
7072         {
7073                 if (IsCurrentFocused())
7074                 {
7075                         editState = EDIT_STATUS_HIGHLIGHTED;
7076                 }
7077                 else if (__isTouchPressed)
7078                 {
7079                         editState = EDIT_STATUS_PRESSED;
7080                 }
7081         }
7082         else
7083         {
7084                 editState = EDIT_STATUS_DISABLED;
7085         }
7086
7087         return editState;
7088 }
7089
7090 _VisualElement*
7091 _EditPresenter::GetCursorVisualElement(void) const
7092 {
7093         return __pCursorVisualElement;
7094 }
7095
7096 void
7097 _EditPresenter::SetMaxLineCount(int maxLineCount)
7098 {
7099         __pEditModel->SetMaxLineCount(maxLineCount);
7100
7101         return;
7102 }
7103
7104 int
7105 _EditPresenter::GetMaxLineCount(void) const
7106 {
7107         return __pEditModel->GetMaxLineCount();
7108 }
7109
7110 result
7111 _EditPresenter::UpdateComponentInformation(void)
7112 {
7113         result r = E_SUCCESS;
7114
7115         if (__isCursorChanged == false)
7116         {
7117                 return r;
7118         }
7119
7120         bool IsTextAlignmentChanged = AdjustRTLTextAlignment(EDIT_TEXT_TYPE_INPUT);
7121         bool setFirstDisplayLine = true;
7122         if (!((__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE) || (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)))
7123         {
7124                 float firstDisplayY = __pTextObject->GetFirstDisplayPositionYF();
7125                 float totalHeight = __pTextObject->GetTotalHeightF();
7126                 FloatRectangle displayBounds = __pTextObject->GetBoundsF();
7127                 if (totalHeight >= displayBounds.height)
7128                 {
7129                         float textGapFromBottom = displayBounds.height - (totalHeight - firstDisplayY);
7130                         if (textGapFromBottom > 0)
7131                         {
7132                                 ScrollText(-textGapFromBottom);
7133                         }
7134                 }
7135                 else
7136                 {
7137                         if (firstDisplayY > 0)
7138                         {
7139                                 ScrollText(-firstDisplayY);
7140                         }
7141                 }
7142
7143                 FloatRectangle absCursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
7144                 CalculateAbsoluteCursorBounds(__cursorPos, absCursorBounds);
7145                 setFirstDisplayLine = (IsContained(absCursorBounds) == false);
7146         }
7147
7148         if (setFirstDisplayLine || IsTextAlignmentChanged)
7149         {
7150                 if (__pTextObject->IsChanged())
7151                 {
7152                         __pTextObject->Compose();
7153                 }
7154                 __pTextObject->SetFirstDisplayLineIndexFromTextIndex(__cursorPos);
7155         }
7156
7157         __pTextObject->SetCursorIndex(__cursorPos);
7158
7159         __isCursorChanged = false;
7160
7161         return r;
7162 }
7163
7164 void
7165 _EditPresenter::ScrollText(float distance)
7166 {
7167         float newFirstDisplayY = __pTextObject->GetFirstDisplayPositionYF();
7168         newFirstDisplayY += distance;
7169
7170         int moveLine = __pTextObject->GetLineIndexAtPositionY(newFirstDisplayY);
7171
7172         __pTextObject->SetFirstDisplayLineIndex(moveLine);
7173         __pTextObject->SetFirstDisplayPositionY(newFirstDisplayY);
7174
7175         return;
7176 }
7177
7178 bool
7179 _EditPresenter::IsContained(FloatRectangle& paramRect) const
7180 {
7181         FloatRectangle absBounds = __pEdit->GetAbsoluteBoundsF(true);
7182
7183         if ((paramRect.x < absBounds.x) ||
7184                 (paramRect.y < absBounds.y) ||
7185                 ((paramRect.x + paramRect.width) > (absBounds.x + absBounds.width)) ||
7186                 ((paramRect.y + paramRect.height) > (absBounds.y + absBounds.height)))
7187         {
7188                 return false;
7189         }
7190
7191         return true;
7192 }
7193
7194 result
7195 _EditPresenter::CalculateAbsoluteCursorBounds(int index, FloatRectangle& absCursorBounds, bool clipCursorHeight)
7196 {
7197         float cursorAbsX = 0.0f;
7198         float cursorAbsY = 0.0f;
7199         float cursorWidth = 0.0f;
7200         float cursorHeight = 0.0f;
7201         float cursorRelativeX = 0.0f;
7202         float cursorRelativeY = 0.0f;
7203
7204         FloatRectangle absBounds = __pEdit->GetAbsoluteBoundsF(true);
7205
7206         __pTextObject->SetBounds(GetTextBoundsF());
7207         if (index != __cursorPos)
7208         {
7209                 if (__pTextObject->GetTextPositionInfoAt(index, cursorWidth, cursorHeight, cursorAbsX, cursorAbsY, cursorRelativeX, cursorRelativeY) != E_SUCCESS)
7210                 {
7211                         return E_SYSTEM;
7212                 }
7213         }
7214         else
7215         {
7216                 if (__pTextObject->GetTextPositionInfoAt(__rowCursorIndex, __columnCursorIndex, cursorWidth, cursorHeight, cursorAbsX, cursorAbsY, cursorRelativeX, cursorRelativeY) != E_SUCCESS)
7217                 {
7218                         return E_SYSTEM;
7219                 }
7220         }
7221
7222         absCursorBounds.x = absBounds.x + cursorRelativeX;
7223
7224         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
7225         {
7226                 FloatRectangle tempBounds;
7227                 GetCursorBounds(true, tempBounds);
7228                 absCursorBounds.y = tempBounds.y;
7229         }
7230         else
7231         {
7232                 absCursorBounds.y = absBounds.y + cursorRelativeY;
7233         }
7234
7235         GET_SHAPE_CONFIG(EDIT::CURSOR_WIDTH, __pEdit->GetOrientation(), cursorWidth);
7236
7237         absCursorBounds.width = cursorWidth;
7238
7239         if (cursorHeight > 0.0f)
7240         {
7241                 if (cursorHeight <= __calculatedCursorBounds.height || !clipCursorHeight)
7242                 {
7243                         absCursorBounds.height = cursorHeight;
7244                 }
7245                 else
7246                 {
7247                         if (__calculatedCursorBounds.height > 0)
7248                         {
7249                                 absCursorBounds.height = __calculatedCursorBounds.height;
7250                         }
7251                         else
7252                         {
7253                                 absCursorBounds.height = cursorHeight;
7254                         }
7255                 }
7256         }
7257         else
7258         {
7259                 absCursorBounds.height = __pTextObject->GetLineHeightAtF(0);
7260         }
7261
7262         return E_SUCCESS;
7263 }
7264
7265 result
7266 _EditPresenter::CalculateAbsoluteCursorBounds(int rowIndex, int columnIndex, FloatRectangle& absCursorBounds, bool clipCursorHeight)
7267 {
7268         float cursorAbsX = 0.0f;
7269         float cursorAbsY = 0.0f;
7270         float cursorWidth = 0.0f;
7271         float cursorHeight = 0.0f;
7272         float cursorRelativeX = 0.0f;
7273         float cursorRelativeY = 0.0f;
7274
7275         FloatRectangle absBounds = __pEdit->GetAbsoluteBoundsF(true);
7276
7277         __pTextObject->SetBounds(GetTextBoundsF());
7278
7279         if (__pTextObject->GetTextPositionInfoAt(rowIndex, columnIndex, cursorWidth, cursorHeight, cursorAbsX, cursorAbsY, cursorRelativeX, cursorRelativeY) != E_SUCCESS)
7280         {
7281                 return E_SYSTEM;
7282         }
7283
7284         absCursorBounds.x = absBounds.x + cursorRelativeX;
7285
7286         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
7287         {
7288                 FloatRectangle tempBounds;
7289                 GetCursorBounds(true, tempBounds);
7290                 absCursorBounds.y = tempBounds.y;
7291         }
7292         else
7293         {
7294                 absCursorBounds.y = absBounds.y + cursorRelativeY;
7295         }
7296
7297         GET_SHAPE_CONFIG(EDIT::CURSOR_WIDTH, __pEdit->GetOrientation(), cursorWidth);
7298
7299         absCursorBounds.width = cursorWidth;
7300
7301         if (cursorHeight > 0.0f)
7302         {
7303                 if (cursorHeight <= __calculatedCursorBounds.height || !clipCursorHeight)
7304                 {
7305                         absCursorBounds.height = cursorHeight;
7306                 }
7307                 else
7308                 {
7309                         if (__calculatedCursorBounds.height > 0)
7310                         {
7311                                    absCursorBounds.height = __calculatedCursorBounds.height;
7312                         }
7313                         else
7314                         {
7315                                    absCursorBounds.height = cursorHeight;
7316                         }
7317                 }
7318         }
7319         else
7320         {
7321                 absCursorBounds.height = __pTextObject->GetLineHeightAtF(0);
7322         }
7323
7324         return E_SUCCESS;
7325 }
7326
7327 result
7328 _EditPresenter::GetCursorBounds(bool isAbsRect, FloatRectangle& cursorBounds)
7329 {
7330         if (__isInitialized == false)
7331         {
7332                 return E_SYSTEM;
7333         }
7334
7335         CalculateCursorBounds(GetTextBoundsF(), cursorBounds);
7336
7337         if (isAbsRect)
7338         {
7339                 FloatRectangle absBounds = __pEdit->GetAbsoluteBoundsF(true);
7340                 cursorBounds.x += absBounds.x;
7341                 cursorBounds.y += absBounds.y;
7342         }
7343
7344         return E_SUCCESS;
7345 }
7346
7347
7348 void
7349 _EditPresenter::SetCursorDisabled(bool disabled)
7350 {
7351         __isCursorDisabled = disabled;
7352
7353         return;
7354 }
7355
7356 bool
7357 _EditPresenter::IsGuideTextActivated(void) const
7358 {
7359         if (__pGuideTextObject == null)
7360         {
7361                 return false;
7362         }
7363
7364         if (GetGuideText().IsEmpty())
7365         {
7366                 return false;
7367         }
7368
7369         if (__pTextObject && GetTextLength() > 0)
7370         {
7371                 return false;
7372         }
7373
7374         return true;
7375 }
7376
7377 _Button*
7378 _EditPresenter::CreateCommandButtonItemN(int actionId, const String& text)
7379 {
7380         result r = E_SUCCESS;
7381         _Button* pButton = _Button::CreateButtonN();
7382         SysTryReturn(NID_UI_CTRL, pButton, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
7383
7384         float textSize = 0.0f;
7385
7386         r = pButton->SetActionId(actionId);
7387         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7388
7389         r = pButton->SetText(text);
7390         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7391
7392         r = GET_SHAPE_CONFIG(FOOTER::FOOTER_ITEM_FONT_SIZE, __pEdit->GetOrientation(), textSize);
7393         if (!IsFailed(r))
7394         {
7395                 r = pButton->SetTextSize(textSize);
7396                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7397         }
7398
7399         return pButton;
7400
7401 CATCH:
7402         delete pButton;
7403
7404         return null;
7405 }
7406
7407 result
7408 _EditPresenter::SetKeypadCommandButton(const FloatRectangle& bounds)
7409 {
7410         // This function must be changed after _ toolbar completes their float conversion works
7411         result r = E_SUCCESS;
7412         Bitmap* pNormalBackgroundBitmap = null;
7413         Bitmap* pReplacementColorBackgroundBitmap = null;
7414         String leftButtonText;
7415         String rightButtonText;
7416         _Control* pParent = null;
7417         Color commandBackgroundColor;
7418
7419         if (__pCommandButton)
7420         {
7421                 __pCommandButton->SetResizable(true);
7422                 __pCommandButton->SetMovable(true);
7423                 SysLog(NID_UI_CTRL, "Command position changed!!! bounds(%f, %f, %f, %f)", bounds.x, bounds.y, bounds.width, bounds.height);
7424                 r = __pCommandButton->SetBounds(bounds);
7425
7426                 __pCommandButton->SetResizable(false);
7427                 __pCommandButton->SetMovable(false);
7428
7429                 return r;
7430         }
7431
7432         if (__pParentForm == false)
7433         {
7434                 __isKeypadCommandButtonVisible = false;
7435                 return r;
7436         }
7437
7438         __pCommandButton = _Toolbar::CreateToolbarN(false);
7439         SysTryReturn(NID_UI_CTRL, __pCommandButton, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
7440
7441         r = __pCommandButton->Construct();
7442         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7443
7444         GET_BITMAP_CONFIG_N(FOOTER::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pNormalBackgroundBitmap);
7445         if (pNormalBackgroundBitmap)
7446         {
7447                 GET_COLOR_CONFIG(FOOTER::BG_NORMAL, commandBackgroundColor);
7448                 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pNormalBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), commandBackgroundColor);
7449
7450                 if (pReplacementColorBackgroundBitmap)
7451                 {
7452                         r = __pCommandButton->SetBackgroundBitmap(*pReplacementColorBackgroundBitmap);
7453                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7454
7455                         delete pReplacementColorBackgroundBitmap;
7456                         pReplacementColorBackgroundBitmap = null;
7457                 }
7458                 delete pNormalBackgroundBitmap;
7459                 pNormalBackgroundBitmap = null;
7460         }
7461
7462         r = __pCommandButton->SetStyle(TOOLBAR_COMMAND);
7463         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7464
7465         __pCommandButton->SetResizable(true);
7466         __pCommandButton->SetMovable(true);
7467         SysLog(NID_UI_CTRL, "Command created!!! bounds(%f, %f, %f, %f)", bounds.x, bounds.y, bounds.width, bounds.height);
7468         r = __pCommandButton->SetBounds(bounds);
7469         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7470
7471         __pCommandButton->SetResizable(false);
7472         __pCommandButton->SetMovable(false);
7473
7474         leftButtonText = __pEditModel->GetKeypadCommandButtonText(COMMAND_BUTTON_POSITION_LEFT);
7475         r = __pCommandButton->AddItem(CreateCommandButtonItemN(__pEditModel->GetKeypadCommandButtonActionId(COMMAND_BUTTON_POSITION_LEFT), leftButtonText));
7476         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7477
7478         rightButtonText = __pEditModel->GetKeypadCommandButtonText(COMMAND_BUTTON_POSITION_RIGHT);
7479         r = __pCommandButton->AddItem(CreateCommandButtonItemN(__pEditModel->GetKeypadCommandButtonActionId(COMMAND_BUTTON_POSITION_RIGHT), rightButtonText));
7480         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7481
7482         if (__pActionEventListener)
7483         {
7484                 __pCommandButton->AddActionEventListener(*__pActionEventListener);
7485         }
7486
7487         if (__pParentForm)
7488         {
7489                 r = __pParentForm->AttachChild(*__pCommandButton);
7490                 __pParentForm->MoveChildToTop(*__pCommandButton);
7491         }
7492         else
7493         {
7494                 pParent = __pEdit->GetParent();
7495                 SysTryCatch(NID_UI_CTRL, pParent, r = E_SYSTEM, r, "[%s] Propagating.", GetErrorMessage(r));
7496                 r = pParent->AttachChild(*__pCommandButton);
7497         }
7498         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
7499
7500         return r;
7501
7502 CATCH:
7503         delete pNormalBackgroundBitmap;
7504
7505         delete __pCommandButton;
7506         __pCommandButton = null;
7507
7508         delete pReplacementColorBackgroundBitmap;
7509
7510         return r;
7511 }
7512
7513 void
7514 _EditPresenter::CheckInitialFooterVisibleState(void)
7515 {
7516         if (__pParentForm == null)
7517         {
7518                 return;
7519         }
7520
7521         _Toolbar* pFooter = __pParentForm->GetFooter();
7522         if (pFooter)
7523         {
7524                 if (pFooter->GetVisibleState() == false)
7525                 {
7526                         __initialFooterVisibleStatus = EDIT_FOOTER_VISIBLE_STATUS_HIDE;
7527                         SysLog(NID_UI_CTRL, "EDIT_FOOTER_VISIBLE_STATUS_HIDE");
7528                 }
7529                 else
7530                 {
7531                         __initialFooterVisibleStatus = EDIT_FOOTER_VISIBLE_STATUS_SHOW;
7532                         SysLog(NID_UI_CTRL, "EDIT_FOOTER_VISIBLE_STATUS_SHOW");
7533                 }
7534         }
7535         else
7536         {
7537                 __initialFooterVisibleStatus = EDIT_FOOTER_VISIBLE_STATUS_NONE;
7538                 SysLog(NID_UI_CTRL, "EDIT_FOOTER_VISIBLE_STATUS_NONE");
7539         }
7540
7541         return;
7542 }
7543
7544 void
7545 _EditPresenter::SetFooterVisible(bool isVisible)
7546 {
7547         if (__pParentForm == null)
7548         {
7549                 return;
7550         }
7551
7552         _Toolbar* pFooter = __pParentForm->GetFooter();
7553         if (pFooter && __initialFooterVisibleStatus == EDIT_FOOTER_VISIBLE_STATUS_SHOW)
7554         {
7555                 if ((isVisible == true && pFooter->GetVisibleState() == false) ||
7556                         (isVisible == false && pFooter->GetVisibleState() == true))
7557                 {
7558                         if (isVisible)
7559                         {
7560                                 SysLog(NID_UI_CTRL, "SetFooterVisible TRUE!!!");
7561                         }
7562                         else
7563                         {
7564                                 SysLog(NID_UI_CTRL, "SetFooterVisible FALSE!!!");
7565                         }
7566
7567                         __footerVisibleChanged = true;
7568                         pFooter->SetVisibleState(isVisible);
7569                         pFooter->Invalidate();
7570
7571                         if (isVisible)
7572                         {
7573                                 __initialFooterVisibleStatus = EDIT_FOOTER_VISIBLE_STATUS_NONE;
7574                         }
7575                 }
7576         }
7577
7578         return;
7579 }
7580
7581 result
7582 _EditPresenter::ShowFullscreenKeypad(void)
7583 {
7584         result r = E_SUCCESS;
7585
7586         if (__isCopyPasteManagerExist)
7587         {
7588                 InitializeCopyPasteManager();
7589         }
7590
7591         if (IsKeypadEnabled() == false)
7592         {
7593                 __pEdit->SetFocused();
7594                 return E_SUCCESS;
7595         }
7596
7597         if (__pFullscreenKeypad)
7598         {
7599                 __pFullscreenKeypad->Close();
7600                 delete __pFullscreenKeypad;
7601                 __pFullscreenKeypad = null;
7602         }
7603
7604         __isKeypadExist = CheckKeypadExist(__pEdit->GetOrientation());
7605         if (__isKeypadExist) //overlay style keypad exist before create fullscreen edit.
7606         {
7607                 AdjustParentPanelHeight(true);
7608
7609                 //Do not use the Draw() API. If we use the Draw() API, it's possible to occur the memory crash.
7610                 if (__pParentForm)
7611                 {
7612                         SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
7613                         __pParentForm->DeflateClientRectHeight(0);
7614                         __pParentForm->Invalidate(true);
7615                 }
7616         }
7617
7618         int editStyle = __pEdit->GetEditStyle();
7619
7620         _KeypadStyleInfo keypadStyleInfo;
7621         keypadStyleInfo.keypadStyle = __pEditModel->GetKeypadStyle();
7622         keypadStyleInfo.textPredictionEnabled = __pEditModel->IsTextPredictionEnabled();
7623         keypadStyleInfo.isNormalNumberStyle = __isKeypadNormalNumberStyleEnabled;
7624         keypadStyleInfo.enterActionEnabled = true;
7625         keypadStyleInfo.isLowerCaseModeEnabled = __pEditModel->IsLowerCaseModeEnabled();
7626
7627         bool inputConnectionBoundState = __isInputConnectionBound;
7628         __isInputConnectionBound = true;
7629         SetKeypadStyle(__pEditModel->GetKeypadStyle());
7630         __isInputConnectionBound = inputConnectionBoundState;
7631
7632         if (editStyle & EDIT_STYLE_SINGLE_LINE)
7633         {
7634                 keypadStyleInfo.enterActionEnabled = false;
7635         }
7636
7637         if (editStyle & EDIT_STYLE_PASSWORD)
7638         {
7639                 editStyle = EDIT_STYLE_NORMAL | EDIT_STYLE_SINGLE_LINE | EDIT_STYLE_PASSWORD;
7640         }
7641         else
7642         {
7643                 editStyle = EDIT_STYLE_NORMAL;
7644         }
7645
7646         __pFullscreenKeypad = _Keypad::CreateKeypadN();
7647         SysTryReturn(NID_UI_CTRL, __pFullscreenKeypad, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
7648         r = __pFullscreenKeypad->Initialize(editStyle, keypadStyleInfo, GetTextLimitLength(), __pEdit);
7649         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
7650
7651         __pFullscreenKeypad->SetText(GetText());
7652
7653         r = __pFullscreenKeypad->Open();
7654         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
7655
7656         if (__pEdit->IsInputEventEnabled())
7657         {
7658                 __pEdit->LockInputEvent();
7659         }
7660
7661         if (__pTextFilter)
7662         {
7663                 __pFullscreenKeypad->SetEditTextFilter(this);
7664         }
7665         return r;
7666 }
7667
7668 void
7669 _EditPresenter::DeleteFullscreenKeypad(void)
7670 {
7671         if (__pFullscreenKeypad)
7672         {
7673                 __pFullscreenKeypad->Close();
7674                 delete __pFullscreenKeypad;
7675                 __pFullscreenKeypad = null;
7676         }
7677
7678         return;
7679 }
7680
7681 result
7682 _EditPresenter::GetKeypadBounds(FloatRectangle& bounds)
7683 {
7684         if (__pInputConnection == null)
7685         {
7686                 return E_SYSTEM;
7687         }
7688
7689         bounds = __pInputConnection->GetInputPanelBoundsF();
7690
7691         _CoordinateSystem* pCoordSystem = _CoordinateSystem::GetInstance();
7692         SysTryReturnResult(NID_UI_CTRL, pCoordSystem, E_SYSTEM, "Coordinate system load failed.");
7693
7694         _ICoordinateSystemTransformer* pXformer = pCoordSystem->GetInverseTransformer();
7695         SysTryReturnResult(NID_UI_CTRL, pXformer, E_SYSTEM, "Coordinate system load failed.");
7696
7697         bounds = pXformer->Transform(bounds);
7698         __keypadBounds = bounds;
7699
7700         return E_SUCCESS;
7701 }
7702
7703 float
7704 _EditPresenter::GetClipboardHeight(void) const
7705 {
7706         return __clipboardHeight;
7707 }
7708
7709 bool
7710 _EditPresenter::IsKeypadRotating(_ControlOrientation orientation)
7711 {
7712         FloatDimension screenSize;
7713         FloatRectangle absKeypadBounds(0.0f, 0.0f, 0.0f, 0.0f);
7714         _ControlManager* pControlManager = _ControlManager::GetInstance();
7715
7716         GetKeypadBounds(absKeypadBounds);
7717
7718         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
7719         {
7720                 screenSize.height = pControlManager->GetScreenSizeF().height;
7721                 screenSize.width = pControlManager->GetScreenSizeF().width;
7722         }
7723         else
7724         {
7725                 screenSize.height = pControlManager->GetScreenSizeF().width;
7726                 screenSize.width = pControlManager->GetScreenSizeF().height;
7727         }
7728
7729         if (absKeypadBounds.width == screenSize.width)
7730         {
7731                 return false;
7732         }
7733         else
7734         {
7735                 return true;
7736         }
7737 }
7738
7739 bool
7740 _EditPresenter::CheckKeypadExist(_ControlOrientation orientation)
7741 {
7742         FloatDimension screenSize;
7743         FloatRectangle absKeypadBounds(0.0f, 0.0f, 0.0f, 0.0f);
7744         _ControlManager* pControlManager = _ControlManager::GetInstance();
7745
7746         GetKeypadBounds(absKeypadBounds);
7747
7748         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
7749         {
7750                 screenSize.height = pControlManager->GetScreenSizeF().height;
7751                 screenSize.width = pControlManager->GetScreenSizeF().width;
7752         }
7753         else
7754         {
7755                 screenSize.height = pControlManager->GetScreenSizeF().width;
7756                 screenSize.width = pControlManager->GetScreenSizeF().height;
7757         }
7758
7759         if (absKeypadBounds.width != 0 && absKeypadBounds.height != 0)
7760         {
7761                 if ((absKeypadBounds.y != screenSize.height))
7762                 {
7763                         SysLog(NID_UI_CTRL, "KEYPAD EXIST!!!Keypad(y: %f, w: %f, h: %f)", absKeypadBounds.y, absKeypadBounds.width, absKeypadBounds.height);
7764                         return true;
7765                 }
7766                 else
7767                 {
7768                         SysLog(NID_UI_CTRL, "NO KEYPAD!!!Keypad(y: %f, w: %f, h: %f)", absKeypadBounds.y, absKeypadBounds.width, absKeypadBounds.height);
7769                         return false;
7770                 }
7771         }
7772         else
7773         {
7774                 SysLog(NID_UI_CTRL, "NO KEYPAD!!!Keypad(y: %f, w: %f, h: %f)", absKeypadBounds.y, absKeypadBounds.width, absKeypadBounds.height);
7775                 return false;
7776         }
7777 }
7778
7779 result
7780 _EditPresenter::ShowKeypad(bool focus)
7781 {
7782         if (!__pEdit->IsVisible())
7783         {
7784                 return E_SUCCESS;
7785         }
7786
7787         if (IsKeypadEnabled() == false)
7788         {
7789                 return E_SUCCESS;
7790         }
7791
7792         if (focus)
7793         {
7794                 __pEdit->SetFocused();
7795                 return E_SUCCESS;
7796         }
7797
7798         if (!__isInitialized)
7799         {
7800                 return E_SUCCESS;
7801         }
7802
7803         _ControlManager* pControlManager = _ControlManager::GetInstance();
7804
7805         if (!pControlManager->IsFrameActivated())
7806         {
7807                 return E_SUCCESS;
7808         }
7809
7810         bool sendKeypadEventForcely = false;
7811
7812         CheckUSBKeyboardStatus();
7813
7814         __isInputConnectionBound = true;
7815
7816         SetKeypadStyle(__pEditModel->GetKeypadStyle());
7817
7818         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE && GetKeypadAction() == CORE_KEYPAD_ACTION_ENTER)
7819         {
7820                 __pInputConnection->SetInputPanelActionEnabled(false);
7821         }
7822         else
7823         {
7824                 __pInputConnection->SetInputPanelAction(ConvertKeypadAction(GetKeypadAction()));
7825         }
7826
7827         //Need to complete AutoCapitalization functionality
7828         if (__pEditModel->IsLowerCaseModeEnabled())
7829         {
7830                 __pInputConnection->SetAutoCapitalizationMode(AUTO_CAPITALIZATION_MODE_NONE);
7831         }
7832         else
7833         {
7834                 __pInputConnection->SetAutoCapitalizationMode(AUTO_CAPITALIZATION_MODE_SENTENCE);
7835         }
7836
7837         __pInputConnection->BindInputMethod();
7838         __isKeypadShowing = true;
7839         __isKeypadHiding = false;
7840         __resizedByKeypadHide = false;
7841         __latestBoundedContext = (unsigned int)this;
7842
7843         LanguageCode initialKeypadLanguage = LANGUAGE_INVALID;
7844         __pEditModel->GetInitialKeypadLanguage(initialKeypadLanguage);
7845         if (initialKeypadLanguage != LANGUAGE_INVALID)
7846         {
7847                 SetCurrentLanguage(initialKeypadLanguage);
7848         }
7849         //layout rearrange
7850         if (__isUSBKeyboardConnected)
7851         {
7852                 SysLog(NID_UI_CTRL, "ShowKeypad called in USB ON mode!!!");
7853
7854                 __isKeypadExist = CheckKeypadExist(__pEdit->GetOrientation()); //prediction alreaedy exists
7855
7856                 if (__isKeypadCommandButtonVisible)
7857                 {
7858                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CREATED);
7859                         __pEdit->AttachScrollPanelEvent();
7860                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CREATED);
7861
7862                         if (__initialFooterVisibleStatus == EDIT_FOOTER_VISIBLE_STATUS_NONE)
7863                         {
7864                                 CheckInitialFooterVisibleState();
7865                         }
7866
7867                         SetFooterVisible(false);
7868                         ChangeLayoutInternal(__pEdit->GetOrientation());
7869                         AdjustParentPanelHeight(false);
7870                         ScrollPanelToCursorPosition();
7871
7872                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_OPEN);
7873                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_OPENED);
7874
7875                         //Do not use the Draw() API. If we use the Draw() API, it's possible to occur the memory crash.
7876                         if (__pParentForm)
7877                         {
7878                                 __pParentForm->Invalidate(true);
7879                         }
7880                 }
7881                 else
7882                 {
7883                         if (__initialFooterVisibleStatus == EDIT_FOOTER_VISIBLE_STATUS_NONE)
7884                         {
7885                                 CheckInitialFooterVisibleState();
7886                         }
7887
7888                         if (__isKeypadExist)
7889                         {
7890                                 if (__pParentForm)
7891                                 {
7892                                         sendKeypadEventForcely = !__pParentForm->IsDeflated();
7893                                 }
7894
7895                                 if (sendKeypadEventForcely)
7896                                 {
7897                                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CREATED);
7898                                         __pEdit->AttachScrollPanelEvent();
7899                                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CREATED);
7900                                 }
7901
7902                                 ChangeLayoutInternal(__pEdit->GetOrientation());
7903                                 AdjustParentPanelHeight(false);
7904                                 ScrollPanelToCursorPosition();
7905
7906                                 //Do not use the Draw() API. If we use the Draw() API, it's possible to occur the memory crash.
7907                                 if (__pParentForm)
7908                                 {
7909                                         __pParentForm->Invalidate(true);
7910                                 }
7911
7912                                 if (sendKeypadEventForcely)
7913                                 {
7914                                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_OPEN);
7915                                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_OPENED);
7916                                 }
7917                         }
7918                         else
7919                         {
7920                                 ScrollPanelToCursorPosition();
7921                         }
7922                 }
7923         }
7924         else
7925         {
7926                 SysLog(NID_UI_CTRL, "ShowKeypad called in USB OFF mode!!!");
7927
7928                 __isKeypadExist = CheckKeypadExist(__pEdit->GetOrientation()); //call once only from here.
7929
7930                 if (!__isKeypadExist)
7931                 {
7932                         if (__isKeypadCommandButtonVisible)
7933                         {
7934                                 if (!__pCommandButton || (__pCommandButton && !__pCommandButton->GetVisibleState()))
7935                                 {
7936                                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CREATED);
7937                                         __pEdit->AttachScrollPanelEvent();
7938                                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CREATED);
7939                                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_OPEN);
7940                                         __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_OPENED);
7941                                 }
7942                         }
7943                         else
7944                         {
7945                                 if (!__isClipboardExist)
7946                                 {
7947                                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CREATED);
7948                                 }
7949                                 __pEdit->AttachScrollPanelEvent();
7950                                 __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CREATED);
7951                         }
7952
7953                         if (__initialFooterVisibleStatus == EDIT_FOOTER_VISIBLE_STATUS_NONE)
7954                         {
7955                                 CheckInitialFooterVisibleState();
7956                         }
7957                 }
7958                 else
7959                 {
7960                         if (__footerVisibleChanged)
7961                         {
7962                                 SetFooterVisible(true);
7963                         }
7964
7965                         if (__initialFooterVisibleStatus == EDIT_FOOTER_VISIBLE_STATUS_NONE)
7966                         {
7967                                 CheckInitialFooterVisibleState();
7968                         }
7969                 }
7970
7971                 if (__isKeypadCommandButtonVisible)
7972                 {
7973                         SetFooterVisible(false);
7974                 }
7975
7976                 if (__isKeypadExist) //edit switiching
7977                 {
7978                         if (__pParentForm)
7979                         {
7980                                 sendKeypadEventForcely = !__pParentForm->IsDeflated();
7981                         }
7982
7983                         if (sendKeypadEventForcely)
7984                         {
7985                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CREATED);
7986                                 __pEdit->AttachScrollPanelEvent();
7987                                 __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_CREATED);
7988                         }
7989
7990                         ChangeLayoutInternal(__pEdit->GetOrientation());
7991                         AdjustParentPanelHeight(false);
7992                         ScrollPanelToCursorPosition();
7993
7994                         //Do not use the Draw() API. If we use the Draw() API, it's possible to occur the memory crash.
7995                         if (__pParentForm)
7996                         {
7997                                 __pParentForm->Invalidate(true);
7998                         }
7999                         __isKeypadShowing = false;
8000
8001                         if (sendKeypadEventForcely)
8002                         {
8003                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_OPEN);
8004                                 __pEdit->SendScrollPanelEvent(CORE_OVERLAY_CONTROL_OPENED);
8005                         }
8006                 }
8007                 else
8008                 {
8009                         if(!__isClipboardExist && __pParentPanel)
8010                         {
8011                                 if (__initialParentHeight)
8012                                 {
8013                                         AdjustParentPanelHeight(true);
8014                                 }
8015                         }
8016                         ScrollPanelToCursorPosition();
8017                 }
8018
8019                 __pInputConnection->ShowInputPanel();
8020         }
8021
8022         return E_SUCCESS;
8023 }
8024
8025 result
8026 _EditPresenter::ChangeLayout(_ControlOrientation orientation)
8027 {
8028         result r = E_SUCCESS;
8029
8030         //for Target DND
8031         __pDragAndDropCueVisualElement->SetShowState(false);
8032
8033         if (__dragAndDropStarted)
8034         {
8035                 ResetDragAndDrop();
8036         }
8037
8038         if (__pCopyPasteManager)
8039         {
8040                 if (__pCopyPasteManager->GetCopyPastePopup())
8041                 {
8042                         __needToCreateCopyPastePopup = true;
8043                 }
8044                 __pCopyPasteManager->ReleaseCopyPastePopup();
8045                 __pCopyPasteManager->ReleaseHandle();
8046         }
8047
8048         bool isScrollPanelBoundsReloaded = false;
8049
8050         if (__pParentPanel)
8051         {
8052                 _ControlImpl* pParentPanelImpl = static_cast <_ControlImpl* >(__pParentPanel->GetUserData());
8053                 Rectangle builderBounds;
8054                 isScrollPanelBoundsReloaded= pParentPanelImpl->GetBuilderBounds(orientation, builderBounds);
8055         }
8056
8057         __rotated = true;
8058
8059         CheckUSBKeyboardStatus();
8060
8061         if (__isInputConnectionBound || __clipboardConnected)
8062         {
8063                 SysLog(NID_UI_CTRL, "-------------------ChangeLayout------------------------");
8064
8065                 if (!isScrollPanelBoundsReloaded)
8066                 {
8067                         SysLog(NID_UI_CTRL, "ScrollPanel bounds is not changed by UIBuilder, so forcely reset ScrollPanel's height");
8068                         AdjustParentPanelHeight(true);
8069                 }
8070                 else
8071                 {
8072                         SysLog(NID_UI_CTRL, "ScrollPanel bounds is changed by UIBuilder");
8073                 }
8074
8075                 if (__pParentForm)
8076                 {
8077                         SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
8078                         __pParentForm->DeflateClientRectHeight(0.0f);
8079                 }
8080
8081                 if (__pCommandButton && __isKeypadCommandButtonVisible)
8082                 {
8083                         __pCommandButton->SetVisibleState(false);
8084                 }
8085
8086                 if (__isKeypadExist && ! __isClipboardExist) //only keypad exists, already get keypadbounds before callback [Causion]this timing clipboard height is still previous height
8087                 {
8088                         if (isScrollPanelBoundsReloaded)
8089                         {
8090                                 __initialParentHeight = 0.0f;
8091                         }
8092
8093                         ChangeLayoutInternal(orientation);
8094                         AdjustParentPanelHeight(false);
8095                         ScrollPanelToCursorPosition();
8096                 }
8097                 else // if clipboard exists, boundsChanged callback will delivered after rotate callback
8098                 {
8099                         /*
8100                         if (__isClipboardExist)
8101                         {
8102                                 __initialParentHeight = 0.0f;
8103                         }
8104                         else //no keypad, no clipboard
8105                         {
8106                                 if (__isKeypadCommandButtonVisible)
8107                                 {
8108                                         __initialParentHeight = 0.0f;
8109                                         ChangeLayoutInternal(orientation);
8110                                         AdjustParentPanelHeight(false);
8111                                         ScrollPanelToCursorPosition();
8112                                 }
8113                         }*/
8114
8115                         if (!__isClipboardExist)
8116                         {
8117                                 if (__isKeypadCommandButtonVisible)
8118                                 {
8119                                         __initialParentHeight = 0.0f;
8120                                         ChangeLayoutInternal(orientation);
8121                                         AdjustParentPanelHeight(false);
8122                                 }
8123                                 ScrollPanelToCursorPosition();
8124                         }
8125                 }
8126         }
8127
8128         if ((__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE) == false)
8129         {
8130                 __initialBounds = __pEdit->GetBoundsF();
8131         }
8132
8133         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to change layout.", GetErrorMessage(r));
8134
8135         return r;
8136 }
8137
8138 result
8139 _EditPresenter::ChangeLayout(_ControlRotation rotation)
8140 {
8141         _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
8142
8143         if (rotation == _CONTROL_ROTATION_0 || rotation == _CONTROL_ROTATION_180)
8144         {
8145                 orientation = _CONTROL_ORIENTATION_PORTRAIT;
8146         }
8147         else
8148         {
8149                 orientation = _CONTROL_ORIENTATION_LANDSCAPE;
8150         }
8151
8152         return ChangeLayout(orientation);
8153 }
8154
8155 result
8156 _EditPresenter::ChangeLayoutInternal(_ControlOrientation orientation, bool deflateForm)
8157 {
8158         result r = E_SUCCESS;
8159
8160         FloatRectangle keypadBounds(0.0f, 0.0f, 0.0f, 0.0f);
8161
8162         _ControlManager* pControlManager = _ControlManager::GetInstance();
8163         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
8164
8165         _Frame* pCurrentFrame = dynamic_cast<_Frame*>(pControlManager->GetCurrentFrame());
8166         if (!pCurrentFrame || (pCurrentFrame && pCurrentFrame->GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN))
8167         {
8168                 if (pCurrentFrame)
8169                 {
8170                         SysLog(NID_UI_CTRL, "FrameShowMode[%d]", pCurrentFrame->GetShowMode());
8171                 }
8172                 else
8173                 {
8174                         SysLog(NID_UI_CTRL, "Frame is null");
8175                 }
8176                 return r;
8177         }
8178
8179         FloatDimension screenSize;
8180         FloatRectangle commandButtonBounds(0.0f, 0.0f, 0.0f, 0.0f);
8181
8182         float formDeflateHeight = 0.0f;
8183         float shrinkedHeight = 0.0f;
8184
8185         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
8186         {
8187                 screenSize.width = pControlManager->GetScreenSizeF().width;
8188                 screenSize.height = pControlManager->GetScreenSizeF().height;
8189         }
8190         else
8191         {
8192                 screenSize.width = pControlManager->GetScreenSizeF().height;
8193                 screenSize.height = pControlManager->GetScreenSizeF().width;
8194         }
8195
8196         if (__isInputConnectionBound || __clipboardConnected)
8197         {
8198                 GetKeypadBounds(keypadBounds);
8199
8200                 if (__isKeypadExist)
8201                 {
8202                         if (__isClipboardExist)
8203                         {
8204                                 if (__clipboardHeight > keypadBounds.height)
8205                                 {
8206                                         shrinkedHeight = __clipboardHeight;
8207                                 }
8208                                 else
8209                                 {
8210                                         shrinkedHeight = keypadBounds.height;
8211                                 }
8212                         }
8213                         else
8214                         {
8215                                 shrinkedHeight = keypadBounds.height;
8216                         }
8217                 }
8218                 else
8219                 {
8220                         if (__isClipboardExist)
8221                         {
8222                                 shrinkedHeight = __clipboardHeight;
8223                         }
8224                 }
8225
8226                 if (__isKeypadCommandButtonVisible)
8227                 {
8228                         commandButtonBounds.width = screenSize.width;
8229                         float commandButtonHeight = 0.0f;
8230
8231                         if (__pParentForm)
8232                         {
8233                                 GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, commandButtonHeight);
8234                                 commandButtonBounds.height = commandButtonHeight;
8235                                 formDeflateHeight += commandButtonBounds.height;
8236
8237                                 if (__isKeypadExist || __isClipboardExist)
8238                                 {
8239                                         formDeflateHeight += shrinkedHeight;
8240                                         commandButtonBounds.y = screenSize.height - shrinkedHeight - commandButtonBounds.height - __pParentForm->GetClientBoundsF().y;
8241                                 }
8242                                 else
8243                                 {
8244                                         commandButtonBounds.y = screenSize.height - commandButtonBounds.height - __pParentForm->GetClientBoundsF().y;
8245                                 }
8246
8247                                 SetKeypadCommandButton(commandButtonBounds);
8248
8249                                 if (__pCommandButton)
8250                                 {
8251                                         __pCommandButton->SetVisibleState(true);
8252                                         __pCommandButton->Invalidate();
8253                                 }
8254                         }
8255                 }
8256                 else
8257                 {
8258                         if (__pParentForm)
8259                         {
8260                                 if (__isKeypadExist || __isClipboardExist)
8261                                 {
8262                                         formDeflateHeight += shrinkedHeight;
8263                                 }
8264                         }
8265                 }
8266         }
8267
8268         if (__pParentForm && deflateForm)
8269         {
8270                 SysLog(NID_UI_CTRL, "FormDeflateHeight:%f, KeypadExist(%d), ClipboardExist(%d), CommandButtonVisible(%d)",
8271                         formDeflateHeight, __isKeypadExist, __isClipboardExist, __isKeypadCommandButtonVisible);
8272                 __pParentForm->DeflateClientRectHeight(formDeflateHeight);
8273         }
8274
8275         return r;
8276 }
8277
8278 void
8279 _EditPresenter::OnScrollPanelBoundsChanged(void)
8280 {
8281         return;
8282 }
8283
8284 void
8285 _EditPresenter::AdjustParentPanelHeight(bool restore)
8286 {
8287         if (__pParentPanel == null)
8288         {
8289                 SysLog(NID_UI_CTRL, "__pParentPanel is NULL!!!, so skip resizing scrollpanel");
8290                 return;
8291         }
8292
8293         _ControlManager* pControlManager = _ControlManager::GetInstance();
8294         SysTryReturnVoidResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "[E_SYSTEM] Failed to get root.");
8295
8296         _Frame* pCurrentFrame = dynamic_cast<_Frame*>(pControlManager->GetCurrentFrame());
8297         if (!pCurrentFrame || (pCurrentFrame && pCurrentFrame->GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN))
8298         {
8299                 if (pCurrentFrame)
8300                 {
8301                         SysLog(NID_UI_CTRL, "FrameShowMode[%d]", pCurrentFrame->GetShowMode());
8302                 }
8303                 else
8304                 {
8305                         SysLog(NID_UI_CTRL, "Frame is null");
8306                 }
8307                 return;
8308         }
8309
8310         float initialParentHeight = __initialParentHeight;
8311         if (__pResizedPanel != __pParentPanel)
8312         {
8313                 initialParentHeight = 0.0f;
8314         }
8315
8316         _ControlOrientation orientation;
8317         float commandButtonHeight = 0.0f;
8318
8319         FloatRectangle absKeypadBounds(0.0f, 0.0f, 0.0f, 0.0f);
8320
8321         _Toolbar* pFooter = null;
8322
8323         if (__pParentForm)
8324         {
8325                 pFooter = __pParentForm->GetFooter();
8326         }
8327
8328         FloatRectangle absScrollPanelBounds(0.0f, 0.0f, 0.0f, 0.0f);
8329         FloatRectangle scrollPanelBounds = __pParentPanel->GetBoundsF();
8330         float gapY = 0.0f;
8331
8332         float displayedPanelHeight = 0.0f;
8333         FloatDimension screenSize;
8334
8335         if (__pEdit->GetOrientation()== _CONTROL_ORIENTATION_PORTRAIT)
8336         {
8337                 screenSize.width = pControlManager->GetScreenSizeF().width;
8338                 screenSize.height = pControlManager->GetScreenSizeF().height;
8339         }
8340         else
8341         {
8342                 screenSize.width = pControlManager->GetScreenSizeF().height;
8343                 screenSize.height = pControlManager->GetScreenSizeF().width;
8344         }
8345
8346         if (restore)
8347         {
8348                 if (initialParentHeight)
8349                 {
8350                         scrollPanelBounds.height = __initialParentHeight;
8351                         SysLog(NID_UI_CTRL, "Rollback ScrollPanel's height to %f and Set __initialParentHeight to 'Zero' ", __initialParentHeight);
8352                         __initialParentHeight = 0.0f;
8353                         __pResizedPanel = null;
8354                         __pParentPanel->SetBounds(scrollPanelBounds);
8355                         __pParentPanel->Invalidate();
8356                 }
8357                 else
8358                 {
8359                         SysLog(NID_UI_CTRL, "initialParentHeight is ZERO!!!, so skip scrollPanel height recovery!!!");
8360                 }
8361         }
8362         else
8363         {
8364                 if (__isKeypadExist)
8365                 {
8366                         GetKeypadBounds(absKeypadBounds);
8367
8368                         if (__isClipboardExist)
8369                         {
8370                                 if (__clipboardHeight > absKeypadBounds.height)
8371                                 {
8372                                         absKeypadBounds.y = screenSize.height - __clipboardHeight;
8373                                 }
8374                         }
8375                         else
8376                         {
8377                                 if (__isUSBKeyboardConnected)//predictive window shown
8378                                 {
8379                                         absKeypadBounds.y = screenSize.height - absKeypadBounds.height;//only absKeypadBounds.height is meaningful in USB on.
8380                                 }
8381                         }
8382                 }
8383                 else
8384                 {
8385                         if (__isClipboardExist)
8386                         {
8387                                 absKeypadBounds.y = screenSize.height - __clipboardHeight;
8388                         }
8389                         else
8390                         {
8391                                 absKeypadBounds.y = screenSize.height;
8392                         }
8393                 }
8394
8395                 if ((__pParentForm && __isKeypadCommandButtonVisible) || (pFooter && (pFooter->GetVisibleState() == true)))
8396                 {
8397                         orientation = __pEdit->GetOrientation();
8398                         GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, commandButtonHeight);
8399                 }
8400
8401                 absScrollPanelBounds = __pParentPanel->GetAbsoluteBoundsF(true);
8402                 displayedPanelHeight = screenSize.height - commandButtonHeight - absScrollPanelBounds.y;
8403                 gapY = (absKeypadBounds.y - commandButtonHeight)- absScrollPanelBounds.y;
8404
8405                 bool isOverlapped = true;
8406
8407                 if (((absKeypadBounds.y - commandButtonHeight) >= (absScrollPanelBounds.y + absScrollPanelBounds.height)) || ( absScrollPanelBounds.y > absKeypadBounds.y))
8408                 {
8409                         isOverlapped = false;
8410                 }
8411
8412                 SysLog(NID_UI_CTRL, "IsOverlapped:(%d), __initialParentHeight:(%f), gapY:(%f)", isOverlapped, __initialParentHeight, gapY);
8413
8414                 if (!initialParentHeight)
8415                 {
8416                         if (!isOverlapped)
8417                         {
8418                                 return;
8419                         }
8420
8421                         if (gapY > 0.0f)
8422                         {
8423                                 initialParentHeight = scrollPanelBounds.height;
8424                                 __initialParentHeight = initialParentHeight;
8425                                 __pResizedPanel = __pParentPanel;
8426
8427                                 SysLog(NID_UI_CTRL, "Set ScrollPanel's height to %f and Set __initialParentHeight:(%f)", gapY, __initialParentHeight);
8428
8429                                 scrollPanelBounds.height = gapY;
8430                                 __pParentPanel->SetBounds(scrollPanelBounds);
8431                                 __pParentPanel->Invalidate();
8432                         }
8433                 }
8434                 else
8435                 {
8436                         if (!isOverlapped)
8437                         {
8438                                 if ((gapY < initialParentHeight) && (gapY > 0.0f))
8439                                 {
8440                                         SysLog(NID_UI_CTRL, "Set ScrollPanel's height to %f", gapY);
8441
8442                                         scrollPanelBounds.height = gapY;
8443                                         __pParentPanel->SetBounds(scrollPanelBounds);
8444                                         __pParentPanel->Invalidate();
8445                                         return;
8446                                 }
8447                                 else
8448                                 {
8449                                         if (gapY > initialParentHeight)
8450                                         {
8451                                                 if (scrollPanelBounds.height > initialParentHeight)
8452                                                 {
8453                                                         __initialParentHeight = scrollPanelBounds.height ;
8454                                                         return;
8455                                                 }
8456
8457                                                 SysLog(NID_UI_CTRL, "Set ScrollPanel's height to %f", __initialParentHeight);
8458
8459                                                 scrollPanelBounds.height = initialParentHeight;
8460                                                 __pParentPanel->SetBounds(scrollPanelBounds);
8461                                                 __pParentPanel->Invalidate();
8462                                         }
8463                                         return;
8464                                 }
8465                         }
8466
8467                         if (gapY > 0.0f)
8468                         {
8469                                 if (scrollPanelBounds.height > initialParentHeight)
8470                                 {
8471                                         __initialParentHeight = scrollPanelBounds.height ;
8472                                 }
8473
8474                                 SysLog(NID_UI_CTRL, "Set ScrollPanel's height to %f", gapY);
8475                                 scrollPanelBounds.height = gapY;
8476                                 __pParentPanel->SetBounds(scrollPanelBounds);
8477                                 __pParentPanel->Invalidate();
8478                         }
8479                 }
8480         }
8481 }
8482
8483 result
8484 _EditPresenter::HideKeypad(bool focus)
8485 {
8486         InitializeCopyPasteManager();
8487
8488         __isKeypadShowing = false;
8489         __resizedByKeypadHide = false;
8490
8491         if (__isInitialized == false || !__isInputConnectionBound)
8492         {
8493                 return E_SUCCESS;
8494         }
8495
8496         CheckUSBKeyboardStatus();
8497
8498         if (__isUSBKeyboardConnected)
8499         {
8500                 SysLog(NID_UI_CTRL, "HideKeypad called in USB ON mode!!!");
8501                 if (__pCommandButton && __isKeypadCommandButtonVisible)
8502                 {
8503                         SetFooterVisible(true);
8504
8505                         __pCommandButton->SetVisibleState(false);
8506
8507                         if (__pParentForm)
8508                         {
8509                                 SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
8510                                 __pParentForm->DeflateClientRectHeight(0.0f);
8511                         }
8512
8513                         AdjustParentPanelHeight(true);
8514
8515                         __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CLOSE);
8516                 }
8517         }
8518         else
8519         {
8520                 SysLog(NID_UI_CTRL, "HideKeypad called in USB OFF mode!!!");
8521                 if (__pCommandButton && __isKeypadCommandButtonVisible)
8522                 {
8523                         if (!__isKeypadExist)
8524                         {
8525                                 SetFooterVisible(true);//must be called ahead of DeflateClientRectHeights
8526
8527                                 if (__pParentForm)
8528                                 {
8529                                         SysLog(NID_UI_CTRL, "Form deflate RESET!!!");
8530                                         __pParentForm->DeflateClientRectHeight(0.0f);
8531                                 }
8532                                 __pEdit->SendKeypadEvent(GetKeypadAction(), CORE_KEYPAD_EVENT_STATUS_CLOSE);
8533                         }
8534                         __pCommandButton->SetVisibleState(false);
8535                 }
8536         }
8537
8538         FinishTextComposition();
8539         __pInputConnection->HideInputPanel();
8540         __pInputConnection->UnbindInputMethod();
8541
8542         if (__isKeypadExist)
8543         {
8544                 __isKeypadHiding = true;
8545         }
8546
8547         __isInputConnectionBound = false;
8548
8549         if (focus && __pEdit->IsFocused())
8550         {
8551                 __pEdit->SetFocused(false);
8552         }
8553
8554         return E_SUCCESS;
8555 }
8556
8557 void
8558 _EditPresenter::ChangeKeypadStatus(void)
8559 {
8560         InitializeCopyPasteManager();
8561
8562         if (__isInputConnectionBound)
8563         {
8564                 __isInputConnectionBound = false;
8565         }
8566
8567         return;
8568 }
8569
8570 void
8571 _EditPresenter::OnTimerExpired(Timer& timer)
8572 {
8573         Timer* onTimer = &timer;
8574
8575         if (onTimer == __pCursorTimer)
8576         {
8577                 OnCursorTimerExpired();
8578         }
8579         else if (onTimer == __pTitleSlidingTimer)
8580         {
8581                 OnTitleSlidingTimerExpired();
8582         }
8583         else if (onTimer == __pPasswordTimer)
8584         {
8585                 OnPasswordTimerExpired();
8586         }
8587         else if (onTimer == __pFlickAnimationTimer)
8588         {
8589                 OnFlickTimerExpired();
8590         }
8591
8592         return;
8593 }
8594
8595 void
8596 _EditPresenter::OnEditCopyPasteStatusChanged(CoreCopyPasteStatus status, CoreCopyPasteAction action)
8597 {
8598         switch (action)
8599         {
8600                 case CORE_COPY_PASTE_ACTION_COPY:
8601                         __pEdit->CopyText();
8602                         break;
8603                 case CORE_COPY_PASTE_ACTION_CUT:
8604                         __pEdit->CutText();
8605                         InitializeCopyPasteManager();
8606                         break;
8607                 case CORE_COPY_PASTE_ACTION_PASTE:
8608                         __pEdit->PasteText();
8609                         InitializeCopyPasteManager();
8610                         break;
8611                 case CORE_COPY_PASTE_ACTION_SEARCH:
8612                         InitializeCopyPasteManager();
8613                         break;
8614                 case CORE_COPY_PASTE_ACTION_CLIPBOARD:
8615                         __clipboardConnected = true;
8616                         break;
8617                 default:
8618                         break;
8619         }
8620         __pEdit->Invalidate();
8621
8622         return;
8623 }
8624
8625 result
8626 _EditPresenter::InitializeCursor(void)
8627 {
8628         StopCursorTimer();
8629
8630         if (__isCursorDisabled == false && IsCurrentFocused() && __isTextBlocked == false)
8631         {
8632                 bool outOfRangeInSignleLine = false;
8633                 FloatRectangle cursorBounds;
8634                 if (CalculateCursorBounds(__textObjectBounds, cursorBounds) != E_SUCCESS)
8635                 {
8636                         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
8637                         {
8638                                 outOfRangeInSignleLine = true;
8639                         }
8640                 }
8641
8642                 __pCursorVisualElement->SetOpacity(1.0f);
8643                 __pCursorVisualElement->SetBounds(cursorBounds);
8644
8645                 Canvas* pCanvas = __pCursorVisualElement->GetCanvasN();
8646                 if (pCanvas == null)
8647                 {
8648                         return E_SYSTEM;
8649                 }
8650
8651                 if (outOfRangeInSignleLine)
8652                 {
8653                         __isCursorOpaque = false;
8654                 }
8655                 else
8656                 {
8657                         __isCursorInitialized = false;
8658                 }
8659
8660                 DrawCursor(*pCanvas, cursorBounds, __isCursorOpaque);
8661
8662                 if (__pInputConnection)
8663                 {
8664                         FloatRectangle absoluteEditRectangle;
8665                         if (GetCursorBounds(false, absoluteEditRectangle) == E_SUCCESS)
8666                         {
8667                                 __pInputConnection->SetCursorBounds(absoluteEditRectangle);
8668                         }
8669                 }
8670                 __isCursorOpaque = __isCursorOpaque ? false : true;
8671
8672                 delete pCanvas;
8673
8674                 __previousCursorBounds = cursorBounds;
8675                 StartCursorTimer();
8676         }
8677         else
8678         {
8679                 __pCursorVisualElement->SetOpacity(0);
8680         }
8681
8682         if (__pInputConnection != null && __isInputConnectionBound == true && !__isCopyPasteManagerExist)
8683         {
8684                 __pInputConnection->SetCursorPosition(__cursorPos);
8685         }
8686
8687         return E_SUCCESS;
8688 }
8689
8690 void
8691 _EditPresenter::StopCursorTimer(void)
8692 {
8693         if (__pCursorTimer)
8694         {
8695                 __pCursorTimer->Cancel();
8696         }
8697         return;
8698 }
8699
8700 result
8701 _EditPresenter::StartCursorTimer(void)
8702 {
8703         result r = E_SUCCESS;
8704
8705         if (__pCursorTimer == null)
8706         {
8707                 __pCursorTimer = new (std::nothrow) Timer;
8708                 if (__pCursorTimer == null)
8709                 {
8710                         return E_OUT_OF_MEMORY;
8711                 }
8712
8713                 r = __pCursorTimer->Construct(*this);
8714                 if (IsFailed(r))
8715                 {
8716                         goto CATCH;
8717                 }
8718         }
8719
8720         r = __pCursorTimer->Start(EDIT_CURSOR_TIMER_PERIOD);
8721         if (IsFailed(r))
8722         {
8723                 goto CATCH;
8724         }
8725
8726         return r;
8727
8728 CATCH:
8729         StopCursorTimer();
8730
8731         delete __pCursorTimer;
8732         __pCursorTimer = null;
8733
8734         return r;
8735 }
8736
8737 result
8738 _EditPresenter::DrawCursor(Canvas& canvas, FloatRectangle& cursorBounds, bool isCursorOpaque)
8739 {
8740         result r = E_SUCCESS;
8741
8742         if (__isCursorDisabled == false)
8743         {
8744                 Color cursorColor;
8745                 GET_COLOR_CONFIG(EDIT::CURSOR_NORMAL, cursorColor);
8746
8747                 if (__isCursorInitialized)
8748                 {
8749                         cursorBounds.SetPosition(0.0f, 0.0f);
8750
8751                         if (canvas.GetBackgroundColor() != cursorColor)
8752                         {
8753                                 canvas.FillRectangle(cursorColor, cursorBounds);
8754                         }
8755
8756                         if (isCursorOpaque)
8757                         {
8758                                 __pCursorVisualElement->SetOpacity(1.0f);
8759                         }
8760                         else
8761                         {
8762                                 __pCursorVisualElement->SetOpacity(0);
8763                         }
8764                 }
8765                 else
8766                 {
8767                         cursorBounds.SetPosition(0.0f, 0.0f);
8768
8769                         canvas.FillRectangle(cursorColor, cursorBounds);
8770                         __isCursorInitialized = true;
8771
8772                 }
8773         }
8774         else
8775         {
8776                 __pCursorVisualElement->SetOpacity(0);
8777         }
8778
8779         return r;
8780 }
8781
8782 result
8783 _EditPresenter::MoveCursor(const FloatRectangle& fromRect, const FloatRectangle& toRect)
8784 {
8785    if ((__previousCursorBounds.x != fromRect.x) || (__previousCursorBounds.y != fromRect.y) || (__previousCursorBounds.width != fromRect.width) || (__previousCursorBounds.height != fromRect.height))
8786    {
8787       return E_SYSTEM;
8788    }
8789
8790         __pCursorVisualElement->SetOpacity(0);
8791
8792         __pCursorVisualElement->SetBounds(toRect);
8793         Canvas* pCanvas = __pCursorVisualElement->GetCanvasN();
8794
8795         if (pCanvas == null)
8796         {
8797                 return E_SYSTEM;
8798         }
8799
8800         if (toRect.y < 0.0f || toRect.y >= __clientBounds.height ||
8801                 toRect.x < 0.0f || toRect.x >= __clientBounds.width)
8802         {
8803                 delete pCanvas;
8804                 return E_SYSTEM;
8805         }
8806
8807         __pCursorVisualElement->SetOpacity(1.0f);
8808
8809         Color cursorColor;
8810
8811         GET_COLOR_CONFIG(EDIT::CURSOR_NORMAL, cursorColor);
8812
8813         pCanvas->FillRectangle(cursorColor, toRect);
8814
8815         __previousCursorBounds = toRect;
8816         delete pCanvas;
8817
8818         return E_SUCCESS;
8819 }
8820
8821 void
8822 _EditPresenter::OnCursorTimerExpired(void)
8823 {
8824         if (!IsCurrentFocused() ||  __isCursorDisabled)
8825         {
8826                 StopCursorTimer();
8827                 return;
8828         }
8829
8830         FloatRectangle cursorBounds;
8831
8832         if (CalculateCursorBounds(__textObjectBounds, cursorBounds) != E_SUCCESS)
8833         {
8834                 return;
8835         }
8836
8837         if ((__previousCursorBounds.x != cursorBounds.x) || (__previousCursorBounds.y != cursorBounds.y) || (__previousCursorBounds.width != cursorBounds.width) || (__previousCursorBounds.height != cursorBounds.height))
8838         {
8839                 __previousCursorBounds = cursorBounds;
8840         }
8841
8842         if (__pCursorVisualElement)
8843         {
8844                 __pCursorVisualElement->SetBounds(cursorBounds);
8845                 Canvas* pCanvas = __pCursorVisualElement->GetCanvasN();
8846                 if (pCanvas == null)
8847                 {
8848                         return;
8849                 }
8850
8851                 DrawCursor(*pCanvas, cursorBounds, __isCursorOpaque);
8852
8853                 delete pCanvas;
8854         }
8855
8856         __isCursorOpaque = __isCursorOpaque ? false : true;
8857         StartCursorTimer();
8858
8859         if (__pCopyPasteManager)
8860         {
8861                 __pCopyPasteManager->UpdateCopyPasteMagnifier();
8862         }
8863
8864         return;
8865 }
8866
8867 EllipsisPosition
8868 _EditPresenter::GetEllipsisPosition(void) const
8869 {
8870         return __pEdit->GetEllipsisPosition();
8871 }
8872
8873 result
8874 _EditPresenter::SetEllipsisPosition(EllipsisPosition position)
8875 {
8876         result r = E_SUCCESS;
8877         TextObjectEllipsisType ellipsisType = TEXT_OBJECT_ELLIPSIS_TYPE_TAIL;
8878         if (position == ELLIPSIS_POSITION_START)
8879         {
8880                 ellipsisType = TEXT_OBJECT_ELLIPSIS_TYPE_HEAD;
8881         }
8882         else if (position == ELLIPSIS_POSITION_MIDDLE)
8883         {
8884                 ellipsisType = TEXT_OBJECT_ELLIPSIS_TYPE_MIDDLE;
8885         }
8886
8887         __pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
8888
8889         r = __pTextObject->SetTextObjectEllipsisType(ellipsisType);
8890         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Unable to Set ellipsis position.");
8891
8892         return r;
8893 }
8894
8895 void
8896 _EditPresenter::OnFontInfoRequested(unsigned long& style, float& size)
8897 {
8898         style = __contentFontStyle;
8899         size =  __contentFontSize;
8900
8901         return;
8902 }
8903
8904 void
8905 _EditPresenter::OnFontChanged(Font* pFont)
8906 {
8907         if (!__isFontInitialized)
8908         {
8909                 return;
8910         }
8911
8912         result r = E_SUCCESS;
8913
8914         r = AdjustFont(*pFont, EDIT_FONT_CHANGE_ALL);
8915         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
8916
8917         __titleFontFaceName = pFont->GetFaceName();
8918
8919         return;
8920 }
8921
8922 Font*
8923 _EditPresenter::GetFont(void) const
8924 {
8925         return __pFont;
8926 }
8927
8928 int
8929 _EditPresenter::GetTextSize(void) const
8930 {
8931         return _CoordinateSystemUtils::ConvertToInteger(__contentFontSize);
8932 }
8933
8934 float
8935 _EditPresenter::GetTextSizeF(void) const
8936 {
8937         return __contentFontSize;
8938 }
8939
8940 unsigned int
8941 _EditPresenter::GetFontStyle(const Font* pBaseFont) const
8942 {
8943         unsigned long style = FONT_STYLE_MIN;
8944
8945         if (pBaseFont->IsPlain())
8946         {
8947                 style |= FONT_STYLE_PLAIN;
8948         }
8949         if (pBaseFont->IsItalic())
8950         {
8951                 style |= FONT_STYLE_ITALIC;
8952         }
8953         if (pBaseFont->IsBold())
8954         {
8955                 style |= FONT_STYLE_BOLD;
8956         }
8957
8958         return style;
8959 }
8960
8961 result
8962 _EditPresenter::SetTextSize(const int size)
8963 {
8964         result r = E_SUCCESS;
8965         _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
8966         r = GetLastResult();
8967         SysTryReturn(NID_UI_CTRL, fontImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
8968
8969         r = fontImpl->SetSize(size);
8970         SysTryReturn(NID_UI_CTRL, !(IsFailed(r)), r, r, "SetSize is failed.");
8971
8972         if (__pTextObject)
8973         {
8974                 r = __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
8975                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
8976                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
8977         }
8978
8979         if (IsGuideTextActivated())
8980         {
8981                 r = __pGuideTextObject->SetFont(__pFont, 0, __pGuideTextObject->GetTextLength());
8982                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
8983         }
8984
8985         __contentFontSize = _CoordinateSystemUtils::ConvertToFloat(size);
8986         return r;
8987 }
8988
8989 result
8990 _EditPresenter::SetTextSize(const float size)
8991 {
8992         result r = E_SUCCESS;
8993         _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
8994         r = GetLastResult();
8995         SysTryReturn(NID_UI_CTRL, fontImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
8996
8997         r = fontImpl->SetSize(size);
8998         SysTryReturn(NID_UI_CTRL, !(IsFailed(r)), r, r, "SetSize is failed.");
8999
9000         if (__pTextObject)
9001         {
9002                 r = __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
9003                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
9004                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9005         }
9006
9007         if (IsGuideTextActivated())
9008         {
9009                 r = __pGuideTextObject->SetFont(__pFont, 0, __pGuideTextObject->GetTextLength());
9010                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9011         }
9012
9013         __contentFontSize = size;
9014         return r;
9015 }
9016
9017 result
9018 _EditPresenter::SetFont(const Font& font)
9019 {
9020         result r = E_SUCCESS;
9021
9022         Font* pFont = _FontImpl::CloneN(const_cast <Font&>(font));
9023         SysTryReturnResult(NID_UI_CTRL, pFont, GetLastResult(), "Unable to create font.");
9024
9025         __pFont = pFont;
9026
9027         if (__pTextObject)
9028         {
9029                 r = __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
9030                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
9031                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, GetLastResult(), "Unable to set font.");
9032         }
9033
9034         if (IsGuideTextActivated())
9035         {
9036                 r = __pGuideTextObject->SetFont(__pFont, 0, __pGuideTextObject->GetTextLength());
9037                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, GetLastResult(), "Unable to set font.");
9038         }
9039
9040         return r;
9041 }
9042
9043 result
9044 _EditPresenter::AdjustFont(Font& font, _EditFontChange fontChange)
9045 {
9046         result r = E_SUCCESS;
9047         Font* pFont = &font;
9048
9049         _FontImpl* fontImpl = _FontImpl::GetInstance(*pFont);
9050         r = GetLastResult();
9051         SysTryReturn(NID_UI_CTRL, fontImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
9052
9053         if (fontChange == EDIT_FONT_CHANGE_TITLE || fontChange == EDIT_FONT_CHANGE_ALL)
9054         {
9055                 if (__pTitleTextObject)
9056                 {
9057                         r = fontImpl->SetSize(__titleFontSize);
9058                         SysTryReturn(NID_UI_CTRL, !(IsFailed(r)), r, r, "SetSize is failed.");
9059
9060                         r = __pTitleTextObject->SetFont(pFont, 0, __pTitleTextObject->GetTextLength());
9061                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9062                 }
9063         }
9064
9065         if (fontChange == EDIT_FONT_CHANGE_CONTENT || fontChange == EDIT_FONT_CHANGE_ALL)
9066         {
9067                 r = fontImpl->SetSize(__contentFontSize);
9068                 SysTryReturn(NID_UI_CTRL, !(IsFailed(r)), r, r, "SetSize is failed.");
9069
9070                 unsigned long style = FONT_STYLE_PLAIN;
9071
9072                 if (__contentTextStyle & TEXT_BOX_TEXT_STYLE_BOLD)
9073                 {
9074                         style |= FONT_STYLE_BOLD;
9075                 }
9076                 if (__contentTextStyle & TEXT_BOX_TEXT_STYLE_ITALIC)
9077                 {
9078                         style |= FONT_STYLE_ITALIC;
9079                 }
9080
9081                 fontImpl->SetStyle(style);
9082
9083                 if (__contentTextStyle & TEXT_BOX_TEXT_STYLE_UNDERLINE)
9084                 {
9085                         fontImpl->SetUnderline(true);
9086                 }
9087                 if (__contentTextStyle & TEXT_BOX_TEXT_STYLE_STRIKEOUT)
9088                 {
9089                         fontImpl->SetStrikeOut(true);
9090                 }
9091
9092                 if (__pTextObject)
9093                 {
9094                         r = __pTextObject->SetFont(pFont, 0, __pTextObject->GetTextLength());
9095                         __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
9096                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9097                 }
9098
9099                 if (__pGuideTextObject)
9100                 {
9101                         r = __pGuideTextObject->SetFont(pFont, 0, __pGuideTextObject->GetTextLength());
9102                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9103                 }
9104         }
9105
9106         __pFont = pFont;
9107
9108         if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
9109         {
9110                 ResetTextBounds();
9111         }
9112
9113         return r;
9114 }
9115
9116 String
9117 _EditPresenter::GetTitleFontFaceName(void)
9118 {
9119         return __titleFontFaceName;
9120 }
9121
9122 result
9123 _EditPresenter::GetFontType(String& typefaceName, unsigned long& styleMask) const
9124 {
9125         result r = E_SUCCESS;
9126
9127         if (__pFont)
9128         {
9129                 typefaceName = __pFont->GetFaceName();
9130         }
9131
9132         styleMask = __contentTextStyle;
9133
9134         return r;
9135 }
9136
9137 result
9138 _EditPresenter::SetFontType(const String& typefaceName, unsigned long styleMask)
9139 {
9140         result r = E_SUCCESS;
9141
9142         Font* pFont = null;
9143         IList* systemFontList = Font::GetSystemFontListN();
9144         SysTryReturnResult(NID_UI_CTRL, systemFontList, E_SYSTEM, "Unable to get system font list.\n");
9145
9146         int fontListCount = systemFontList->GetCount();
9147         String tempFontFaceName;
9148         bool isFaceNameAvailable = false;
9149
9150         float textSize = __pFont->GetSizeF();
9151         unsigned long fontStyle = FONT_STYLE_PLAIN;
9152
9153         if (styleMask & TEXT_BOX_TEXT_STYLE_ITALIC)
9154         {
9155                 fontStyle |= FONT_STYLE_ITALIC;
9156         }
9157         if (styleMask & TEXT_BOX_TEXT_STYLE_BOLD)
9158         {
9159                 fontStyle |= FONT_STYLE_BOLD;
9160         }
9161
9162         for (int i = 0; i < fontListCount; i++)
9163         {
9164                 tempFontFaceName = *static_cast<String*>(systemFontList->GetAt(i));
9165
9166                 pFont = new (std::nothrow) Font;
9167                 SysTryCatch(NID_UI_CTRL, pFont, , r = E_OUT_OF_MEMORY, "Memory allocation failed.");
9168                 r = pFont->Construct(tempFontFaceName, fontStyle, textSize);
9169                 SysTryCatch(NID_UI_CTRL, !IsFailed(r), , r, "Unable to construct Font.\n");
9170
9171                 // check font face name.
9172                 if (typefaceName.Equals(pFont->GetFaceName(), true))
9173                 {
9174                         isFaceNameAvailable = true;
9175                         break;
9176                 }
9177
9178                 delete pFont;
9179                 pFont = null;
9180         }
9181
9182         SysTryCatch(NID_UI_CTRL, isFaceNameAvailable, , r = E_INVALID_ARG, "The unsupported font face name is given.\n");
9183
9184         if (styleMask & TEXT_BOX_TEXT_STYLE_UNDERLINE)
9185         {
9186                 pFont->SetUnderline(true);
9187         }
9188         if (styleMask & TEXT_BOX_TEXT_STYLE_STRIKEOUT)
9189         {
9190                 pFont->SetStrikeOut(true);
9191         }
9192
9193         __contentFontStyle = fontStyle;
9194         __contentTextStyle = styleMask;
9195
9196         __pFont = pFont;
9197
9198         systemFontList->RemoveAll(true);
9199         delete systemFontList;
9200         systemFontList = null;
9201
9202         if (__pTextObject)
9203         {
9204                 r = __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
9205                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
9206                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, GetLastResult(), "Unable to set font.");
9207         }
9208
9209         return r;
9210 CATCH:
9211         if (pFont)
9212         {
9213                 delete pFont;
9214                 pFont = null;
9215         }
9216
9217         systemFontList->RemoveAll(true);
9218         delete systemFontList;
9219         systemFontList = null;
9220
9221         return r;
9222 }
9223
9224 unsigned long
9225 _EditPresenter::GetTextStyle(void) const
9226 {
9227         return __contentTextStyle;
9228 }
9229
9230 result
9231 _EditPresenter::SetTextStyle(unsigned long textStyle)
9232 {
9233         result r = E_SUCCESS;
9234
9235         _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
9236         r = GetLastResult();
9237         SysTryReturn(NID_UI_CTRL, fontImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
9238
9239         unsigned long style = FONT_STYLE_PLAIN;
9240
9241         if (textStyle & TEXT_BOX_TEXT_STYLE_BOLD)
9242         {
9243                 style |= FONT_STYLE_BOLD;
9244         }
9245         if (textStyle & TEXT_BOX_TEXT_STYLE_ITALIC)
9246         {
9247                 style |= FONT_STYLE_ITALIC;
9248         }
9249
9250         fontImpl->SetStyle(style);
9251
9252         if (textStyle & TEXT_BOX_TEXT_STYLE_UNDERLINE)
9253         {
9254                 fontImpl->SetUnderline(true);
9255         }
9256         else
9257         {
9258                 fontImpl->SetUnderline(false);
9259         }
9260
9261         if (textStyle & TEXT_BOX_TEXT_STYLE_STRIKEOUT)
9262         {
9263                 fontImpl->SetStrikeOut(true);
9264         }
9265         else
9266         {
9267                 fontImpl->SetStrikeOut(false);
9268         }
9269
9270         if (__pTextObject)
9271         {
9272                 r = __pTextObject->SetFont(__pFont, 0, __pTextObject->GetTextLength());
9273                 __ContentTextStatus = EDIT_TEXT_STATUS_COMPOSE_NON;
9274                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9275         }
9276
9277         if (IsGuideTextActivated())
9278         {
9279                 r = __pGuideTextObject->SetFont(__pFont, 0, __pGuideTextObject->GetTextLength());
9280                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Unable to set font.");
9281         }
9282
9283         __contentTextStyle = textStyle;
9284
9285         return r;
9286 }
9287
9288 String
9289 _EditPresenter::GetGuideText(void) const
9290 {
9291         return __guideText;
9292 }
9293
9294 result
9295 _EditPresenter::SetGuideText(const String& guideText)
9296 {
9297         result r = E_SUCCESS;
9298
9299         int length = guideText.GetLength();
9300
9301         __guideText = String(guideText);
9302         wchar_t* tempString = const_cast<wchar_t*>(__guideText.GetPointer());
9303
9304         // guide text
9305         if (__pGuideTextObject != null)
9306         {
9307                 delete __pGuideTextObject;
9308                 __pGuideTextObject = null;
9309         }
9310
9311         __pGuideTextObject = new (std::nothrow) TextObject;
9312         if (__pGuideTextObject == null)
9313         {
9314                 return E_OUT_OF_MEMORY;
9315         }
9316         __pGuideTextObject->Construct();
9317         TextSimple* pSimpleText = new (std::nothrow)TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
9318         __pGuideTextObject->AppendElement(*pSimpleText);
9319
9320         __pGuideTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
9321         __pGuideTextObject->SetFont(__pFont, 0, __pGuideTextObject->GetTextLength());
9322
9323         AdjustRTLTextAlignment(EDIT_TEXT_TYPE_GUIDE);
9324
9325         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE))
9326         {
9327                 __pGuideTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_CHARACTER);
9328         }
9329         else
9330         {
9331                 __pGuideTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
9332         }
9333
9334         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
9335
9336         return r;
9337 }
9338
9339 String
9340 _EditPresenter::GetTitleText(void) const
9341 {
9342         return __titleText;
9343 }
9344
9345 result
9346 _EditPresenter::SetTitleText(const String& title)
9347 {
9348         result r = E_SUCCESS;
9349
9350         int length = title.GetLength();
9351
9352         __titleText = String(title);
9353         wchar_t* tempString = const_cast<wchar_t*>(__titleText.GetPointer());
9354
9355         if (__pTitleTextObject != null)
9356         {
9357                 delete __pTitleTextObject;
9358                 __pTitleTextObject = null;
9359         }
9360
9361         __pTitleTextObject = new (std::nothrow) TextObject;
9362         if (__pTitleTextObject == null)
9363         {
9364                 return E_OUT_OF_MEMORY;
9365         }
9366         __pTitleTextObject->Construct();
9367         TextSimple* pSimpleText = new (std::nothrow)TextSimple(tempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
9368         __pTitleTextObject->AppendElement(*pSimpleText);
9369
9370         AdjustRTLTextAlignment(EDIT_TEXT_TYPE_TITLE);
9371         __pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
9372         __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
9373         __pTitleTextObject->Compose();
9374
9375         float titleFontSize = 0.0f;
9376         GET_SHAPE_CONFIG(EDIT::DEFAULT_TITLE_FONT_SIZE, __pEdit->GetOrientation(), titleFontSize);
9377
9378         __titleFontSize = titleFontSize;
9379
9380         _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
9381         SysTryReturn(NID_UI_CTRL, fontImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
9382
9383         r = fontImpl->SetSize(__titleFontSize);
9384         SysTryReturn(NID_UI_CTRL, !(IsFailed(r)), r, r, "SetSize is failed.");
9385
9386         __pTitleTextObject->SetFont(__pFont, 0, __pTitleTextObject->GetTextLength());
9387
9388         r = fontImpl->SetSize(__contentFontSize);
9389         SysTryReturn(NID_UI_CTRL, !(IsFailed(r)), r, r, "SetSize is failed.");
9390
9391         __pEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
9392
9393         return r;
9394 }
9395
9396 int
9397 _EditPresenter::GetTextLineCount(void) const
9398 {
9399         if (GetTextLength() == 0)
9400         {
9401                 return 0;
9402         }
9403
9404         if (__isInitialized == false)
9405         {
9406                 __pTextObject->SetBounds(__textObjectBounds);
9407                 __pTextObject->Compose();
9408         }
9409
9410         return __pTextObject->GetTotalLineCount();
9411 }
9412
9413 int
9414 _EditPresenter::GetTextTotalHeight(void) const
9415 {
9416         if (GetTextLength() == 0)
9417         {
9418                 return 0;
9419         }
9420
9421         if (__isInitialized == false)
9422         {
9423                 __pTextObject->SetBounds(__textObjectBounds);
9424                 __pTextObject->Compose();
9425         }
9426
9427         return __pTextObject->GetTotalHeight();
9428 }
9429
9430 float
9431 _EditPresenter::GetTextTotalHeightF(void) const
9432 {
9433         if (GetTextLength() == 0)
9434         {
9435                 return 0;
9436         }
9437
9438         if (__isInitialized == false)
9439         {
9440                 __pTextObject->SetBounds(__textObjectBounds);
9441                 __pTextObject->Compose();
9442         }
9443
9444         return __pTextObject->GetTotalHeightF();
9445 }
9446
9447 result
9448 _EditPresenter::Resize(void)
9449 {
9450         SetClientBounds();
9451         SetInitialBounds();
9452
9453         __pTextObject->SetBounds(__textObjectBounds);
9454         __pTextObject->Compose();
9455         __isCursorChanged = true;
9456         __pTextObject->ConvertToRowColumn(__cursorPos, __rowCursorIndex, __columnCursorIndex);
9457
9458          __pTextObject->SetFirstDisplayLineIndex(0);
9459          __pTextObject->SetFirstDisplayPositionY(0);
9460
9461         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL))
9462         {
9463                 if (__pScrollBar == null)
9464                 {
9465                         __pScrollBar = _Scroll::CreateScrollN(*__pEdit,
9466                                                                         SCROLL_DIRECTION_VERTICAL,
9467                                                                         true,
9468                                                                         false,
9469                                                                         false,
9470                                                                         false,
9471                                                                         1,
9472                                                                         1,
9473                                                                         0);
9474                         SysTryReturn(NID_UI_CTRL, __pScrollBar != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the scroll.");
9475                         __pEdit->AttachSystemChild(*__pScrollBar);
9476                 }
9477                 __pScrollBar->SetScrollVisibility(false);
9478                 __pScrollBar->OnParentBoundsChanged();
9479         }
9480
9481         __verticalMargin = __pEdit->GetBoundsF().height - __textObjectBounds.height;
9482
9483         if (__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE)
9484         {
9485                 if (__initialBounds.height > __verticalMargin)
9486                 {
9487                         if (__initialBounds.height > __pEdit->GetBoundsF().height)
9488                         {
9489                                 __prevTotalTextHeight = __initialBounds.height - __verticalMargin;
9490                         }
9491                         else
9492                         {
9493                                 __prevTotalTextHeight = __pEdit->GetBoundsF().height - __verticalMargin;
9494                         }
9495                 }
9496         }
9497
9498         if (__isInputConnectionBound)
9499         {
9500                 SysLog(NID_UI_CTRL, "Edit's bounds chagned, scroll position should be recalculated.");
9501                 ScrollPanelToCursorPosition();
9502         }
9503
9504         return E_SUCCESS;
9505 }
9506
9507
9508 void
9509 _EditPresenter::SetClientBounds(void)
9510 {
9511         int editStyle = __pEdit->GetEditStyle();
9512
9513         __clientBounds = __pEdit->GetBoundsF();
9514         __clientBounds.x = 0.0f;
9515         __clientBounds.y = 0.0f;
9516
9517         if (!(editStyle & EDIT_STYLE_SINGLE_LINE))
9518         {
9519                 return;
9520         }
9521
9522         float leftBorder = 0.0f;
9523         float rightBorder = 0.0f;
9524         float topBorder = 0.0f;
9525         float bottomBorder = 0.0f;
9526         float leftMargin = 0.0f;
9527         float rightMargin = 0.0f;
9528         float topMargin = 0.0f;
9529         float bottomMargin = 0.0f;
9530         _ControlOrientation orientation = __pEdit->GetOrientation();
9531
9532         GET_SHAPE_CONFIG(EDIT::FIELD_LEFT_MARGIN, orientation, leftMargin);
9533         GET_SHAPE_CONFIG(EDIT::FIELD_RIGHT_MARGIN, orientation, rightMargin);
9534         GET_SHAPE_CONFIG(EDIT::FIELD_TOP_MARGIN, orientation, topMargin);
9535         GET_SHAPE_CONFIG(EDIT::FIELD_BOTTOM_MARGIN, orientation, bottomMargin);
9536
9537         if (editStyle & EDIT_STYLE_TITLE_LEFT)
9538         {
9539                 float titleWidth = 0.0f;
9540                 if (__titleWidth != -1.0f)
9541                 {
9542                         titleWidth = __titleWidth;
9543                 }
9544                 else
9545                 {
9546                         GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_RECT_WIDTH, orientation, titleWidth);
9547                 }
9548
9549                 leftBorder = titleWidth;
9550                 rightBorder = rightMargin;
9551                 topBorder = topMargin;
9552                 bottomBorder = bottomMargin;
9553         }
9554         else if (editStyle & EDIT_STYLE_TITLE_TOP)
9555         {
9556                 result r = E_SUCCESS;
9557                 float titletHeight = 0.0f;
9558                 float titleTextTopMargin = 0.0f;
9559                 GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_RECT_HEIGHT, orientation, titletHeight);
9560                 GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_TEXT_TOP_MARGIN, orientation, titleTextTopMargin);
9561
9562                 _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
9563                 SysTryReturnVoidResult(NID_UI_CTRL, fontImpl != null, E_SYSTEM, "[E_SYSTEM] fontImpl is null.");
9564
9565                 float originalSize = fontImpl->GetSizeF();
9566                 float titleFontSize = 0.0f;
9567                 GET_SHAPE_CONFIG(EDIT::DEFAULT_TITLE_FONT_SIZE, __pEdit->GetOrientation(), titleFontSize);
9568
9569                 r = fontImpl->SetSize(titleFontSize);
9570                 SysTryReturnVoidResult(NID_UI_CTRL, !(IsFailed(r)), r, "[%s] Propagating.", GetErrorMessage(r));
9571
9572                 if (titletHeight < fontImpl->GetMaxHeightF())
9573                 {
9574                         titleTextTopMargin -= (fontImpl->GetMaxHeightF()-titletHeight);
9575                         titletHeight = fontImpl->GetMaxHeightF();
9576                 }
9577
9578                 r = fontImpl->SetSize(originalSize);
9579                 SysTryReturnVoidResult(NID_UI_CTRL, !(IsFailed(r)), r, "[%s] Propagating.", GetErrorMessage(r));
9580
9581                 leftBorder = leftMargin;
9582                 rightBorder = rightMargin;
9583                 topBorder = titletHeight + titleTextTopMargin;
9584                 bottomBorder = bottomMargin;
9585         }
9586
9587         __clientBounds.x = leftBorder;
9588         __clientBounds.y = topBorder;
9589         __clientBounds.width -= leftBorder + rightBorder;
9590         __clientBounds.height -= topBorder + bottomBorder;
9591
9592         return;
9593 }
9594
9595 result
9596 _EditPresenter::AdjustTextBounds(bool clearIconVisible)
9597 {
9598         int editStyle = __pEdit->GetEditStyle();
9599
9600         if (!(editStyle & EDIT_STYLE_CLEAR))
9601         {
9602                 return E_SYSTEM;
9603         }
9604
9605         float clearIconWidth = 0.0f;
9606         _ControlOrientation orientation = __pEdit->GetOrientation();
9607
9608         GET_SHAPE_CONFIG(EDIT::CLEAR_ICON_WIDTH, orientation, clearIconWidth);
9609
9610         if (__pEdit->GetEditStyle() & EDIT_STYLE_CLEAR)
9611         {
9612                 if (clearIconVisible)
9613                 {
9614                         __textObjectBounds.width -= clearIconWidth;
9615                 }
9616                 else
9617                 {
9618                         __textObjectBounds.width += clearIconWidth;
9619                 }
9620         }
9621
9622         float textObectMinimumWidth = 0.0f;
9623         float textObjectMinimumHeight = 0.0f;
9624         GET_SHAPE_CONFIG(EDIT::TEXT_OBJECT_MININMUM_WIDTH, orientation, textObectMinimumWidth);
9625         GET_SHAPE_CONFIG(EDIT::TEXT_OBJECT_MININMUM_HEIGHT, orientation, textObjectMinimumHeight);
9626
9627         if (__textObjectBounds.width < textObectMinimumWidth)
9628         {
9629                 __textObjectBounds.width = textObectMinimumWidth;
9630         }
9631
9632         __pTextObject->SetBounds(__textObjectBounds);
9633         __pTextObject->Compose();
9634         __isCursorChanged = true;
9635
9636         return E_SUCCESS;
9637 }
9638
9639 result
9640 _EditPresenter::SetInitialEditFieldBounds(void)
9641 {
9642         result r = E_SUCCESS;
9643         int editStyle = __pEdit->GetEditStyle();
9644         float bottomMargin = 0.0f;
9645         float textLeftMargin = 0.0f;
9646         float textRightMargin =0.0f;
9647         float textTopMargin = 0.0f;
9648         float textBottomMargin = 0.0f;
9649         float titleTextLeftMargin = 0.0f;
9650         float titleTextRightMargin =0.0f;
9651         float titleTextTopMargin = 0.0f;
9652         float titleTextBottomMargin = 0.0f;
9653         float titletHeight = 0.0f;
9654         _ControlOrientation orientation = __pEdit->GetOrientation();
9655
9656         GET_SHAPE_CONFIG(EDIT::FIELD_BOTTOM_MARGIN, orientation, bottomMargin);
9657         GET_SHAPE_CONFIG(EDIT::FIELD_TEXT_LEFT_MARGIN, orientation, textLeftMargin);
9658         GET_SHAPE_CONFIG(EDIT::FIELD_TEXT_RIGHT_MARGIN, orientation, textRightMargin);
9659         GET_SHAPE_CONFIG(EDIT::FIELD_TEXT_TOP_MARGIN, orientation, textTopMargin);
9660         GET_SHAPE_CONFIG(EDIT::FIELD_TEXT_BOTTOM_MARGIN, orientation, textBottomMargin);
9661         GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_TEXT_LEFT_MARGIN, orientation, titleTextLeftMargin);
9662         GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_TEXT_RIGHT_MARGIN, orientation, titleTextRightMargin);
9663         GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_TEXT_TOP_MARGIN, orientation, titleTextTopMargin);
9664         GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_TEXT_BOTTOM_MARGIN, orientation, titleTextBottomMargin);
9665         GET_SHAPE_CONFIG(EDIT::FIELD_TITLE_RECT_HEIGHT, orientation, titletHeight);
9666
9667         if (!(editStyle & EDIT_STYLE_SINGLE_LINE))
9668         {
9669                 return E_SYSTEM;
9670         }
9671
9672         if (editStyle & EDIT_STYLE_CLEAR)
9673         {
9674                 __isClearIconVisible = false;
9675         }
9676
9677         FloatRectangle bounds = __pEdit->GetBoundsF();
9678         if (editStyle & EDIT_STYLE_TITLE_LEFT)
9679         {
9680                 __textObjectBounds.x = __clientBounds.x + textLeftMargin;
9681                 __textObjectBounds.y = __clientBounds.y + textTopMargin;
9682                 __textObjectBounds.width = __clientBounds.width - textLeftMargin
9683                                                           - textRightMargin;
9684                 __textObjectBounds.height = __clientBounds.height - textTopMargin
9685                                                            - textBottomMargin;
9686
9687                 __titleBounds.x = titleTextLeftMargin;
9688                 __titleBounds.y = titleTextTopMargin;
9689                 __titleBounds.width = bounds.width - __clientBounds.width - __titleBounds.x;
9690                 __titleBounds.height = __clientBounds.height - titleTextTopMargin - titleTextBottomMargin;
9691         }
9692         else if (editStyle & EDIT_STYLE_TITLE_TOP)
9693         {
9694                 __textObjectBounds.x = __clientBounds.x + textLeftMargin;
9695                 __textObjectBounds.y = __clientBounds.y;
9696                 __textObjectBounds.width = __clientBounds.width - textLeftMargin
9697                                                           - textRightMargin;
9698                 __textObjectBounds.height = __clientBounds.height - textBottomMargin;
9699
9700                 __titleBounds.x = titleTextLeftMargin;
9701
9702                 _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
9703                 SysTryReturnResult(NID_UI_CTRL, fontImpl != null, E_SYSTEM, "fontImpl is null.");
9704
9705                 float originalSize = fontImpl->GetSizeF();
9706                 float titleFontSize = 0.0f;
9707                 GET_SHAPE_CONFIG(EDIT::DEFAULT_TITLE_FONT_SIZE, __pEdit->GetOrientation(), titleFontSize);
9708
9709                 r = fontImpl->SetSize(titleFontSize);
9710                 SysTryReturnResult(NID_UI_CTRL, !(IsFailed(r)), r, "SetSize is failed.");
9711
9712                 if (titletHeight < fontImpl->GetMaxHeightF())
9713                 {
9714                         titleTextTopMargin -= (fontImpl->GetMaxHeightF()-titletHeight);
9715                 }
9716
9717                 r = fontImpl->SetSize(originalSize);
9718                 SysTryReturnResult(NID_UI_CTRL, !(IsFailed(r)), r, "SetSize is failed.");
9719
9720                 __titleBounds.y = titleTextTopMargin;
9721                 __titleBounds.width = bounds.width - __titleBounds.x - titleTextRightMargin;
9722                 __titleBounds.height = bounds.height - __titleBounds.y - __clientBounds.height - bottomMargin;
9723         }
9724         else if ((editStyle & EDIT_STYLE_NORMAL) || (editStyle & EDIT_STYLE_CLEAR))
9725         {
9726                 __textObjectBounds = __clientBounds;
9727                 float tempLeftMargin = __pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
9728                 float tempRightMargin = __pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
9729
9730                 if (tempLeftMargin != -1.0f)
9731                 {
9732                         __textObjectBounds.x = __clientBounds.x + tempLeftMargin;
9733                         __textObjectBounds.width = __clientBounds.width - tempLeftMargin;
9734                 }
9735                 else
9736                 {
9737                         __textObjectBounds.x = __clientBounds.x + textLeftMargin;
9738                         __textObjectBounds.width = __clientBounds.width - textLeftMargin;
9739                 }
9740
9741                 if (tempRightMargin != -1.0f)
9742                 {
9743                         __textObjectBounds.width -= tempRightMargin;
9744                 }
9745                 else
9746                 {
9747                         __textObjectBounds.width -= textRightMargin;
9748                 }
9749
9750                 __textObjectBounds.y = __clientBounds.y + textTopMargin;
9751                 __textObjectBounds.height = __clientBounds.height - textTopMargin - textBottomMargin;
9752         }
9753         else
9754         {
9755                 float tempLeftMargin = __pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
9756                 float tempRightMargin = __pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
9757                 if (tempLeftMargin != -1.0f)
9758                 {
9759                         __textObjectBounds.x = __clientBounds.x + tempLeftMargin;
9760                         __textObjectBounds.width = __clientBounds.width - tempLeftMargin;
9761                 }
9762                 else
9763                 {
9764                         __textObjectBounds.x = __clientBounds.x + textLeftMargin;
9765                         __textObjectBounds.width = __clientBounds.width - textLeftMargin;
9766                 }
9767
9768                 if (tempRightMargin != -1.0f)
9769                 {
9770                         __textObjectBounds.width -= tempRightMargin;
9771                 }
9772                 else
9773                 {
9774                         __textObjectBounds.width -= textRightMargin;
9775                 }
9776                 __textObjectBounds.y = __clientBounds.y + textTopMargin;
9777                 __textObjectBounds.height = __clientBounds.height - textTopMargin - textBottomMargin;
9778         }
9779
9780         float textObectMinimumWidth = 0.0f;
9781         float textObjectMinimumHeight = 0.0f;
9782         GET_SHAPE_CONFIG(EDIT::TEXT_OBJECT_MININMUM_WIDTH, orientation, textObectMinimumWidth);
9783         GET_SHAPE_CONFIG(EDIT::TEXT_OBJECT_MININMUM_HEIGHT, orientation, textObjectMinimumHeight);
9784
9785         if (__textObjectBounds.width < textObectMinimumWidth)
9786         {
9787                 __textObjectBounds.width = textObectMinimumWidth;
9788         }
9789
9790         if (__textObjectBounds.height <= textObjectMinimumHeight)
9791         {
9792                 __textObjectBounds.height = __contentFontSize;
9793         }
9794         else if (__textObjectBounds.height < __contentFontSize)
9795         {
9796                 __textObjectBounds.y -= (__contentFontSize - __textObjectBounds.height)/2.0f;
9797                 __textObjectBounds.height = __contentFontSize;
9798         }
9799
9800         if (editStyle & EDIT_STYLE_TITLE_LEFT)
9801         {
9802                 float gap = 0.0f;
9803                 if (__titleBounds.width < textObectMinimumWidth)
9804                 {
9805                         gap = textObectMinimumWidth - __titleBounds.width;
9806                         __titleBounds.width = textObectMinimumWidth;
9807                         __textObjectBounds.x += gap;
9808                 }
9809                 if (__titleBounds.height < __titleFontSize)
9810                 {
9811                         __titleBounds.height = __titleFontSize;
9812                 }
9813         }
9814
9815         return r;
9816 }
9817
9818 result
9819 _EditPresenter::SetInitialBounds(void)
9820 {
9821         result r = E_SUCCESS;
9822         FloatRectangle bounds = __pEdit->GetBoundsF();
9823         int editStyle = __pEdit->GetEditStyle();
9824
9825         if (editStyle & EDIT_STYLE_SINGLE_LINE)
9826         {
9827                 r = SetInitialEditFieldBounds();
9828                 __textBoxBounds.x = 0.0f;
9829                 __textBoxBounds.y = 0.0f;
9830                 __textBoxBounds.width = bounds.width;
9831                 __textBoxBounds.height = bounds.height;
9832
9833                 return r;
9834         }
9835
9836         float leftMargin = 0.0f;
9837         float rightMargin = 0.0f;
9838         float topMargin = 0.0f;
9839         float bottomMargin = 0.0f;
9840         float textLeftMargin = 0.0f;
9841         float textRightMargin =0.0f;
9842         float textTopMargin = 0.0f;
9843         float textBottomMargin = 0.0f;
9844         float titleRectWidth = 0.0f;
9845         float titleRectHeight = 0.0f;
9846         float titleTextLeftMargin = 0.0f;
9847         float titleTextRightMargin = 0.0f;
9848         float titleTextTopMargin = 0.0f;
9849         float titleTextBottomMargin = 0.0f;
9850         float scrollWidth = 0.0f;
9851         _ControlOrientation orientation = __pEdit->GetOrientation();
9852
9853         GET_SHAPE_CONFIG(EDIT::AREA_LEFT_MARGIN, orientation, leftMargin);
9854         GET_SHAPE_CONFIG(EDIT::AREA_RIGHT_MARGIN, orientation, rightMargin);
9855         GET_SHAPE_CONFIG(EDIT::AREA_TOP_MARGIN, orientation, topMargin);
9856         GET_SHAPE_CONFIG(EDIT::AREA_BOTTOM_MARGIN, orientation, bottomMargin);
9857         GET_SHAPE_CONFIG(EDIT::AREA_TEXT_LEFT_MARGIN, orientation, textLeftMargin);
9858         GET_SHAPE_CONFIG(EDIT::AREA_TEXT_RIGHT_MARGIN, orientation, textRightMargin);
9859         GET_SHAPE_CONFIG(EDIT::AREA_TEXT_TOP_MARGIN, orientation, textTopMargin);
9860         GET_SHAPE_CONFIG(EDIT::AREA_TEXT_BOTTOM_MARGIN, orientation, textBottomMargin);
9861         GET_SHAPE_CONFIG(EDIT::AREA_TITLE_RECT_WIDTH, orientation, titleRectWidth);
9862         GET_SHAPE_CONFIG(EDIT::AREA_TITLE_RECT_HEIGHT, orientation, titleRectHeight);
9863         GET_SHAPE_CONFIG(EDIT::AREA_TITLE_TEXT_LEFT_MARGIN, orientation, titleTextLeftMargin);
9864         GET_SHAPE_CONFIG(EDIT::AREA_TITLE_TEXT_RIGHT_MARGIN, orientation, titleTextRightMargin);
9865         GET_SHAPE_CONFIG(EDIT::AREA_TITLE_TEXT_TOP_MARGIN, orientation, titleTextTopMargin);
9866         GET_SHAPE_CONFIG(EDIT::AREA_TITLE_TEXT_BOTTOM_MARGIN, orientation, titleTextBottomMargin);
9867         GET_SHAPE_CONFIG(EDIT::AREA_SCROLL_WIDTH, orientation, scrollWidth);
9868
9869         if (editStyle & EDIT_STYLE_TITLE_TOP)
9870         {
9871                 __textBoxBounds.x = leftMargin;
9872                 __textBoxBounds.y = titleRectHeight + titleTextTopMargin;
9873                 __textBoxBounds.width = bounds.width - leftMargin - rightMargin;
9874                 __textBoxBounds.height = bounds.height - titleRectHeight - titleTextTopMargin - bottomMargin;
9875         }
9876         else if (editStyle & EDIT_STYLE_TITLE_LEFT)
9877         {
9878                 float titleWidth = 0.0f;
9879
9880                 if (__titleWidth != -1.0f)
9881                 {
9882                         titleWidth = __titleWidth;
9883                 }
9884                 else
9885                 {
9886                         titleWidth = titleRectWidth;
9887                 }
9888                 __textBoxBounds.x = titleWidth;
9889                 __textBoxBounds.y = topMargin;
9890                 __textBoxBounds.width = bounds.width - titleWidth - leftMargin;
9891                 __textBoxBounds.height = bounds.height - topMargin - bottomMargin;
9892         }
9893         else
9894         {
9895                 __textBoxBounds.x = 0.0f;
9896                 __textBoxBounds.y = 0.0f;
9897                 __textBoxBounds.width = bounds.width;
9898                 __textBoxBounds.height = bounds.height;
9899         }
9900
9901         // setting textBounds
9902         if (editStyle & EDIT_STYLE_TITLE_TOP)
9903         {
9904                 if (__pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN) != -1.0f)
9905                 {
9906                         __textObjectBounds.x = __textBoxBounds.x + __pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
9907                         __textObjectBounds.width = __textBoxBounds.width - __pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
9908                 }
9909                 else
9910                 {
9911                         __textObjectBounds.x = __textBoxBounds.x + textLeftMargin;
9912                         __textObjectBounds.width = __textBoxBounds.width - textLeftMargin;
9913                 }
9914
9915                 if (__pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN) != -1.0f)
9916                 {
9917                         __textObjectBounds.width -= __pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
9918                 }
9919                 else
9920                 {
9921                         __textObjectBounds.width -= textRightMargin;
9922
9923                 }
9924
9925                 __textObjectBounds.y = __textBoxBounds.y;
9926                 __textObjectBounds.height = __textBoxBounds.height - textBottomMargin;
9927         }
9928         else
9929         {
9930                 if (__pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN) != -1.0f)
9931                 {
9932                         __textObjectBounds.x = __textBoxBounds.x + __pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
9933                         __textObjectBounds.width = __textBoxBounds.width - __pEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
9934                 }
9935                 else
9936                 {
9937                         __textObjectBounds.x = __textBoxBounds.x + textLeftMargin;
9938                         __textObjectBounds.width = __textBoxBounds.width - textLeftMargin;
9939                 }
9940
9941                 if (__pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN) != -1.0f)
9942                 {
9943                         __textObjectBounds.width -= __pEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
9944                 }
9945                 else
9946                 {
9947                         __textObjectBounds.width -= textRightMargin;
9948
9949                 }
9950
9951                 if (__pEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) != -1.0f)
9952                 {
9953                         __textObjectBounds.y = __textBoxBounds.y + __pEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN);
9954                         __textObjectBounds.height = __textBoxBounds.height - __pEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN);
9955                 }
9956                 else
9957                 {
9958                         __textObjectBounds.y = __textBoxBounds.y + textTopMargin;
9959                         __textObjectBounds.height = __textBoxBounds.height - textTopMargin;
9960                 }
9961
9962                 if (__pEdit->GetVerticalMarginF(EDIT_TEXT_BOTTOM_MARGIN) != -1.0f)
9963                 {
9964                         __textObjectBounds.height -= __pEdit->GetVerticalMarginF(EDIT_TEXT_BOTTOM_MARGIN);
9965                 }
9966                 else
9967                 {
9968                         __textObjectBounds.height -= textBottomMargin;
9969                 }
9970         }
9971
9972         if (editStyle & EDIT_STYLE_TITLE_TOP)
9973         {
9974                 __titleBounds.x = titleTextLeftMargin;
9975                 __titleBounds.y = titleTextTopMargin;
9976                 __titleBounds.width = bounds.width - titleTextLeftMargin
9977                                                            - titleTextRightMargin;
9978                 __titleBounds.height = bounds.height - __textBoxBounds.height - __titleBounds.y
9979                                                                 - bottomMargin;
9980
9981         }
9982         else if (editStyle & EDIT_STYLE_TITLE_LEFT)
9983         {
9984                 __titleBounds.x = titleTextLeftMargin;
9985                 __titleBounds.y = titleTextTopMargin;
9986                 __titleBounds.width = bounds.width - __textBoxBounds.width - __titleBounds.x
9987                                                            - titleTextRightMargin;
9988                 __titleBounds.height = __textBoxBounds.height - titleTextTopMargin
9989                                                                 - titleTextBottomMargin;
9990         }
9991
9992         if (editStyle & EDIT_STYLE_NOSCROLL)
9993         {
9994                 __isScrollBarVisible = false;
9995                 __scrollBarBounds.x = 0.0f;
9996                 __scrollBarBounds.y = 0.0f;
9997                 __scrollBarBounds.width = 0.0f;
9998                 __scrollBarBounds.height = 0.0f;
9999         }
10000         else
10001         {
10002                 __scrollBarBounds.width = scrollWidth;
10003
10004                 __scrollBarBounds.x = bounds.width - __scrollBarBounds.width;
10005                 __scrollBarBounds.y = __textBoxBounds.y + textTopMargin;
10006                 __scrollBarBounds.height = __textBoxBounds.height - textTopMargin - textBottomMargin;
10007                 if (__scrollBarBounds.height < 0.0f)
10008                 {
10009                         __scrollBarBounds.height = 0.0f;
10010                 }
10011
10012                 __isScrollBarVisible = true;
10013
10014                 if (editStyle & EDIT_STYLE_TITLE_TOP)
10015                 {
10016                         __titleBounds.width -= __scrollBarBounds.width;
10017                 }
10018         }
10019
10020         float textObectMinimumWidth = 0.0f;
10021         GET_SHAPE_CONFIG(EDIT::TEXT_OBJECT_MININMUM_WIDTH, orientation, textObectMinimumWidth);
10022
10023         if (__textObjectBounds.width < textObectMinimumWidth)
10024         {
10025                 __textObjectBounds.width = textObectMinimumWidth;
10026         }
10027
10028         if (__textObjectBounds.height < __contentFontSize)
10029         {
10030                 __textObjectBounds.height = __contentFontSize;
10031         }
10032
10033         return r;
10034 }
10035
10036 void
10037 _EditPresenter::StopTitleSlidingTimer(void)
10038 {
10039         if (__pTitleSlidingTimer)
10040         {
10041                 __pTitleSlidingTimer->Cancel();
10042                 delete __pTitleSlidingTimer;
10043                 __pTitleSlidingTimer = null;
10044         }
10045
10046         return;
10047 }
10048
10049 result
10050 _EditPresenter::StartTitleSlidingTimer(void)
10051 {
10052         result r = E_SUCCESS;
10053
10054         if (__pTitleSlidingTimer == null)
10055         {
10056                 __pTitleSlidingTimer = new (std::nothrow) Timer;
10057                 if (__pTitleSlidingTimer == null)
10058                 {
10059                         return E_OUT_OF_MEMORY;
10060                 }
10061
10062                 r = __pTitleSlidingTimer->Construct(*this);
10063                 if (IsFailed(r))
10064                 {
10065                         goto CATCH;
10066                 }
10067         }
10068         r = __pTitleSlidingTimer->Start(TITLE_SLIDING_TIME);
10069         if (IsFailed(r))
10070         {
10071                 goto CATCH;
10072         }
10073         return r;
10074
10075 CATCH:
10076         StopTitleSlidingTimer();
10077         return r;
10078 }
10079
10080 result
10081 _EditPresenter::OnTitleSlidingTimerExpired(void)
10082 {
10083         result r = E_SUCCESS;
10084
10085         if (!IsCurrentFocused())
10086         {
10087                 StopTitleSlidingTimer();
10088                 return r;
10089         }
10090
10091         if (__pTitleTextObject->IsChanged())
10092         {
10093                 r = DrawTitleText();
10094                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to draw title text");
10095         }
10096
10097         Canvas* pTitleTextCanvas = __pTitleTextVisualElement->GetCanvasN();
10098         SysTryReturnResult(NID_UI_CTRL, pTitleTextCanvas, E_SYSTEM, "A system error has occurred. Failed to get canvas of VisualElement");
10099
10100         if (__isTouchPressed)
10101         {
10102                 pTitleTextCanvas->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_PRESSED));
10103         }
10104         else
10105         {
10106                 pTitleTextCanvas->SetBackgroundColor(__pEdit->GetColor(EDIT_STATUS_HIGHLIGHTED));
10107         }
10108
10109         pTitleTextCanvas->Clear();
10110         __pTitleTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pTitleTextCanvas));
10111         r = pTitleTextCanvas->Show();
10112
10113         delete pTitleTextCanvas;
10114
10115         r = StartTitleSlidingTimer();
10116
10117         return r;
10118 }
10119
10120 result
10121 _EditPresenter::ChangePasswordToEchoCharacter(int cursorPos, int textLength)
10122 {
10123         result r = E_SUCCESS;
10124
10125         if (!(__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD))
10126         {
10127                 return E_SYSTEM;
10128         }
10129
10130         if (__isPasswordVisible)
10131         {
10132                 return r;
10133         }
10134
10135         StartPasswordTimer();
10136         if (IsBlocked() == true)
10137         {
10138                 __pTextObject->SetRange(cursorPos, textLength);
10139         }
10140         else
10141         {
10142                 __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), 0);
10143         }
10144
10145         return r;
10146 }
10147
10148 void
10149 _EditPresenter::StopPasswordTimer(void)
10150 {
10151         if (__pPasswordTimer)
10152         {
10153                 __pPasswordTimer->Cancel();
10154                 delete __pPasswordTimer;
10155                 __pPasswordTimer = null;
10156         }
10157
10158         return;
10159 }
10160
10161 result
10162 _EditPresenter::StartPasswordTimer(void)
10163 {
10164         result r = E_SUCCESS;
10165
10166         if (__isPasswordVisible)
10167         {
10168                 return r;
10169         }
10170
10171         if (__pPasswordTimer == null)
10172         {
10173                 __pPasswordTimer = new (std::nothrow) Timer;
10174                 if (__pPasswordTimer == null)
10175                 {
10176                         return E_OUT_OF_MEMORY;
10177                 }
10178
10179                 r = __pPasswordTimer->Construct(*this);
10180                 if (IsFailed(r))
10181                 {
10182                         StopPasswordTimer();
10183                         return r;
10184                 }
10185         }
10186
10187         r = __pPasswordTimer->Start(EDIT_PASSWORD_TIMER_PERIOD);
10188         if (IsFailed(r))
10189         {
10190                 StopPasswordTimer();
10191         }
10192
10193         return r;
10194 }
10195
10196 result
10197 _EditPresenter::OnPasswordTimerExpired(void)
10198 {
10199         result r = E_SUCCESS;
10200
10201         if (!IsCurrentFocused())
10202         {
10203                 return E_SYSTEM;
10204         }
10205
10206         ReplaceTextIntoPasswordHyphenString();
10207         if (__composingTextLength > 0)
10208         {
10209                 _FontImpl* fontImpl = _FontImpl::GetInstance(*__pFont);
10210                 SysTryReturnResult(NID_UI_CTRL, fontImpl != null, E_SYSTEM, "fontImpl is null.");
10211                 fontImpl->SetUnderline(false);
10212                 int composingStartPosition =  GetCursorPosition()-__composingTextLength;
10213                 __pTextObject->SetFont(__pFont, composingStartPosition, composingStartPosition+__composingTextLength);
10214         }
10215
10216         __isCursorChanged = true;
10217
10218         __pEdit->Invalidate();
10219
10220         return r;
10221 }
10222
10223 result
10224 _EditPresenter::ReplaceTextIntoPasswordHyphenString(void)
10225 {
10226         result r = E_SUCCESS;
10227
10228         if (__isPasswordVisible)
10229         {
10230                 return r;
10231         }
10232
10233         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
10234         {
10235                 if (GetTextLength() > 0)
10236                 {
10237                         ChangePasswordToEchoCharacter(__pTextBuffer, __echoChar);
10238                         __isCursorChanged = true;
10239                 }
10240         }
10241
10242         return r;
10243 }
10244
10245 result
10246 _EditPresenter::ChangePasswordToEchoCharacter(wchar_t* dspStrBuffer, wchar_t echoChar)
10247 {
10248         result r = E_SUCCESS;
10249
10250         if (__isPasswordVisible)
10251         {
10252                 return r;
10253         }
10254
10255         int bufferLength = GetTextLength();
10256
10257         for (int i = 0; i < bufferLength && i < EDIT_PASSWORD_BUFFER_MAX - 1; i++)
10258         {
10259                 dspStrBuffer[i] = echoChar;
10260         }
10261         dspStrBuffer[bufferLength] = null;
10262         __isCursorChanged = true;
10263
10264         __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), 0);
10265         UpdateComponentInformation();
10266
10267         return r;
10268 }
10269
10270 result
10271 _EditPresenter::ChangePasswordToPlainText(void)
10272 {
10273         result r = E_SUCCESS;
10274
10275         if (__isPasswordVisible == false)
10276         {
10277                 return r;
10278         }
10279
10280         if (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD)
10281         {
10282                 int textLength = GetTextLength();
10283                 if ((textLength > 0) && (textLength <= __limitLength))
10284                 {
10285                         wchar_t* tempString = const_cast<wchar_t*>(__pTextString->GetPointer());
10286                         for (int i = 0; i < textLength; i++)
10287                         {
10288                                 __pTextBuffer[i] = tempString[i];
10289                         }
10290                         __pTextBuffer[textLength] = 0;
10291                         __pTextObject->RemoveAll();
10292                         TextSimple* pSimpleText = new (std::nothrow)TextSimple(__pTextBuffer, textLength,TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, __pFont);
10293                         __pTextObject->AppendElement(*pSimpleText);
10294                         __pTextObject->Compose();
10295                         __isCursorChanged = true;
10296                 }
10297         }
10298
10299         return r;
10300 }
10301
10302 result
10303 _EditPresenter::SetAutoResizingEnabled(bool enable)
10304 {
10305         return __pEditModel->SetAutoResizingEnabled(enable);
10306 }
10307
10308 bool
10309 _EditPresenter::IsAutoResizingEnabled(void) const
10310 {
10311         return __pEditModel->IsAutoResizingEnabled();
10312 }
10313
10314 float
10315 _EditPresenter::CalculateFlexibleHeightF(void)
10316 {
10317         float height = 0.0f;
10318         float expectedEditHeight = __pTextObject->GetTotalHeightF() + __verticalMargin;
10319         int lineCount = __pTextObject->GetTotalLineCount();
10320
10321         if (__pTextObject->GetTotalHeight())
10322         {
10323                 if ((lineCount >= MAX_LINE_NUMBER) && (GetMaxLineCount() > MAX_LINE_NUMBER))
10324                 {
10325                         height = MAX_LINE_NUMBER * __pTextObject->GetLineHeightAtF(0) + __verticalMargin;
10326                         return height;
10327                 }
10328
10329                 float maxHeight = CalculateMaximumFlexibleHeight();
10330
10331                 //If InitialBounds is more than expectedEdit height, set flexible height as initial height
10332                 if (expectedEditHeight < __initialBounds.height)
10333                 {
10334                         height = __initialBounds.height;
10335                 }
10336                 else if (expectedEditHeight >= maxHeight)
10337                 {
10338                         height = maxHeight;
10339                 }
10340                 else
10341                 {
10342                         height = expectedEditHeight;
10343                 }
10344         }
10345         else
10346         {
10347                 height = __initialBounds.height;
10348         }
10349
10350         FloatDimension flexHeightDim = CoordinateSystem::AlignToDevice(FloatDimension(0, height));
10351         return flexHeightDim.height;
10352 }
10353
10354 result
10355 _EditPresenter::AdjustFlexibleHeight(void)
10356 {
10357         result r = E_SUCCESS;
10358
10359         if (__isFlexibleHeightFrozen == true)
10360         {
10361                 return E_SYSTEM;
10362         }
10363
10364         __pTextObject->Compose();
10365
10366         if (__prevTotalTextHeight == __pTextObject->GetTotalHeightF())  // if text height has not changed.
10367         {
10368                 __prevTotalTextHeight = __pTextObject->GetTotalHeightF();
10369                 return E_SYSTEM;
10370         }
10371
10372         // get edit height
10373         FloatRectangle bounds = __pEdit->GetBoundsF();
10374         float calculateHeight = CalculateFlexibleHeightF();
10375
10376         //calculateHeight is being calculated based on AlignToDevice only
10377         if (bounds.height != calculateHeight)
10378         {
10379                 bounds.height = calculateHeight;
10380                 __prevTotalTextHeight = __pTextObject->GetTotalHeightF();
10381
10382                 return SetFlexBounds(bounds);
10383         }
10384         __prevTotalTextHeight = __pTextObject->GetTotalHeight();
10385         return r;
10386 }
10387
10388 result
10389 _EditPresenter::SetFlexBounds(const FloatRectangle& bounds)
10390 {
10391         result r = E_SUCCESS;
10392
10393         _ExpandableEditAreaEventStatus expandableEditAreaStatus = _EXPANDABLE_EDITAREA_EVENT_ADDED;
10394         if (__pEdit->GetBoundsF().height > bounds.height)
10395         {
10396                 expandableEditAreaStatus = _EXPANDABLE_EDITAREA_EVENT_REMOVED;
10397         }
10398         else if (__pEdit->GetBoundsF().height < bounds.height)
10399         {
10400                 expandableEditAreaStatus = _EXPANDABLE_EDITAREA_EVENT_ADDED;
10401         }
10402
10403         _VisualElement* pVisualElement = __pEdit->GetVisualElement();
10404         SysTryReturnResult(NID_UI_CTRL, pVisualElement, E_SYSTEM, "A system error has occurred. Unable to get root visual element.");
10405
10406         //Modify InitialBounds only on User calls and on Orientation change
10407         if (!((__pEdit->GetEditStyle() & EDIT_STYLE_FLEXIBLE) == false))
10408         {
10409                 __updateInitialBounds = false;
10410         }
10411
10412         __pEdit->SetBounds(bounds);
10413         __updateInitialBounds = true;
10414
10415         Resize();
10416
10417         __pEdit->Invalidate();
10418
10419         __prevTotalTextHeight = __pTextObject->GetTotalHeightF();
10420         __pEdit->SendExpandableEditAreaEvent(expandableEditAreaStatus, __pTextObject->GetTotalLineCount());
10421
10422         return r;
10423 }
10424
10425 float
10426 _EditPresenter::CalculateMaximumFlexibleHeight(void)
10427 {
10428         float maxHeight = 0.0f;
10429         int maximumFlexibleLineNumber = GetMaxLineCount();
10430
10431         if (maximumFlexibleLineNumber > 0) // if max line number is set.
10432         {
10433                 maxHeight = maximumFlexibleLineNumber * __pTextObject->GetLineHeightAtF(0) + __verticalMargin;
10434
10435                 FloatDimension dim = __pEdit->GetMaximumSizeF();
10436                 if (maxHeight > dim.height)
10437                 {
10438                         maxHeight = dim.height;
10439                 }
10440         }
10441
10442         return maxHeight;
10443 }
10444
10445 void
10446 _EditPresenter::GetKeypadBoundsEx(Tizen::Graphics::FloatRectangle& bounds) const
10447 {
10448         bounds.x = __keypadBounds.x;
10449         bounds.y = __keypadBounds.y;
10450         bounds.width = __keypadBounds.width;
10451         bounds.height = __keypadBounds.height;
10452         return;
10453 }
10454
10455 _Form*
10456 _EditPresenter::GetParentForm(void)
10457 {
10458         if (!__pEdit)
10459         {
10460                 return null;
10461         }
10462
10463         if (__pParentForm == null)
10464         {
10465                 result r = E_SUCCESS;
10466
10467                 _Form* pForm = null;
10468                 _Control* pControlCore = null;
10469
10470                 for (pControlCore = __pEdit->GetParent(); pForm == null; pControlCore = pControlCore->GetParent())
10471                 {
10472                         if (pControlCore == null)
10473                         {
10474                                 r = E_SYSTEM;
10475                                 goto CATCH;
10476                         }
10477
10478                         pForm = dynamic_cast<_Form*>(pControlCore);
10479                 }
10480                 return pForm;
10481         }
10482
10483 CATCH:
10484         return null;
10485 }
10486
10487 _ScrollPanel*
10488 _EditPresenter::GetParentPanel(void) const
10489 {
10490         return __pParentPanel;
10491 }
10492
10493 result
10494 _EditPresenter::SetKeypadCommandButtonVisible(bool visible)
10495 {
10496         __isKeypadCommandButtonVisible = visible;
10497         return E_SUCCESS;
10498 }
10499
10500 result
10501 _EditPresenter::SetKeypadCommandButton(CommandButtonPosition position, const String& text, int actionId)
10502 {
10503         result r = E_SUCCESS;
10504         FooterItem footerItem;
10505         footerItem.Construct(actionId);
10506         footerItem.SetText(text);
10507         __isKeypadCommandButtonUserSetting = true;
10508
10509         __pEditModel->SetCommandButtonItem(position, actionId, text);
10510         if (__pCommandButton)
10511         {
10512                 _Button* pButton = __pCommandButton->GetItem(static_cast<int>(position));
10513                 if (pButton)
10514                 {
10515                         pButton->SetActionId(actionId);
10516                         pButton->SetText(text);
10517                 }
10518         }
10519
10520         return r;
10521 }
10522
10523 _Toolbar*
10524 _EditPresenter::GetKeypadCommandButton(void) const
10525 {
10526         return __pCommandButton;
10527 }
10528
10529 result
10530 _EditPresenter::AddActionEventListener(const _IActionEventListener& listener)
10531 {
10532         ClearLastResult();
10533
10534         if (__pCommandButton)
10535         {
10536                 __pCommandButton->AddActionEventListener(listener);
10537         }
10538
10539         __pActionEventListener = const_cast<_IActionEventListener*>(&listener);
10540
10541         return E_SUCCESS;
10542 }
10543
10544 result
10545 _EditPresenter::RemoveActionEventListener(const _IActionEventListener& listener)
10546 {
10547         ClearLastResult();
10548
10549         if (__pCommandButton)
10550         {
10551                 __pCommandButton->RemoveActionEventListener(listener);
10552         }
10553
10554         __pActionEventListener = null;
10555
10556         return E_SUCCESS;
10557 }
10558
10559 result
10560 _EditPresenter::SetTextBounds(Rectangle& bounds)
10561 {
10562         __textObjectBounds = _CoordinateSystemUtils::ConvertToFloat(bounds);
10563         if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
10564         {
10565                 __pTextObject->SetBounds(__textObjectBounds);
10566                 __pTextObject->Compose();
10567                 __isCursorChanged = true;
10568         }
10569         return E_SUCCESS;
10570 }
10571
10572 result
10573 _EditPresenter::SetTextBounds(FloatRectangle& bounds)
10574 {
10575         __textObjectBounds = bounds;
10576         if (__pEdit->GetEditStyle() & EDIT_STYLE_TOKEN)
10577         {
10578                 __pTextObject->SetBounds(__textObjectBounds);
10579                 __pTextObject->Compose();
10580                 __isCursorChanged = true;
10581         }
10582         return E_SUCCESS;
10583 }
10584
10585 FloatRectangle
10586 _EditPresenter::GetTextBoundsF(void) const
10587 {
10588         return __textObjectBounds;
10589 }
10590
10591 Rectangle
10592 _EditPresenter::GetTextBounds(void) const
10593 {
10594         return _CoordinateSystemUtils::ConvertToInteger(__textObjectBounds);
10595 }
10596
10597 bool
10598 _EditPresenter::IsKeypadCommandButtonVisible(void) const
10599 {
10600         return __isKeypadCommandButtonVisible;
10601 }
10602
10603 String
10604 _EditPresenter::GetKeypadCommandButtonText(CommandButtonPosition position) const
10605 {
10606         return __pEditModel->GetKeypadCommandButtonText(position);
10607 }
10608
10609 int
10610 _EditPresenter::GetKeypadCommandButtonActionId(CommandButtonPosition position) const
10611 {
10612         return __pEditModel->GetKeypadCommandButtonActionId(position);
10613 }
10614
10615 result
10616 _EditPresenter::DrawScrollBar(void)
10617 {
10618         result r = E_SUCCESS;
10619
10620         if (__pScrollBar == null)
10621         {
10622                 return E_SYSTEM;
10623         }
10624
10625         float totalHeight = __pTextObject->GetTotalHeightF();
10626         float dspHeight = __textObjectBounds.height;
10627         float firstDisplayY = __pTextObject->GetFirstDisplayPositionYF();
10628
10629         if (totalHeight <= dspHeight)
10630         {
10631                 if (__prevTotalTextHeight != 0.0f && __prevTotalTextHeight == totalHeight)  // flexible edit's case
10632                 {
10633                         return E_SUCCESS;
10634                 }
10635
10636                 __pScrollBar->SetScrollRange(1, 1);
10637                 __pScrollBar->SetScrollPosition(0.0f);
10638
10639                 __isScrollBarVisible = false;
10640                 __previousScrollBarPos = 0.0f;
10641                 __previousScrollBarMaxPos = 0.0f;
10642         }
10643         else
10644         {
10645                 if (firstDisplayY > 0)
10646                 {
10647                         __pScrollBar->SetScrollRange(dspHeight, totalHeight);
10648                         __pScrollBar->SetScrollPosition(firstDisplayY);
10649                         __previousScrollBarMaxPos = totalHeight - dspHeight;
10650                 }
10651                 else
10652                 {
10653                         __pScrollBar->SetScrollRange(dspHeight, totalHeight);
10654                         __pScrollBar->SetScrollPosition(0.0f);
10655                         __previousScrollBarMaxPos = 0.0f;
10656                 }
10657
10658                 if (__pScrollBar->GetScrollVisibility())
10659                 {
10660                         __isScrollBarVisible = true;
10661                 }
10662
10663                 __previousScrollBarPos = firstDisplayY;
10664         }
10665
10666         return r;
10667 }
10668
10669 void
10670 _EditPresenter::FadeOutScrollBar(void)
10671 {
10672         if (__pScrollBar)
10673         {
10674                 __pScrollBar->SetScrollVisibility(false);
10675         }
10676         __isScrollBarVisible = false;
10677
10678         return;
10679 }
10680
10681 result
10682 _EditPresenter::InitializeFlickAnimation(void)
10683 {
10684         result r = E_SUCCESS;
10685
10686         if (__pFlickAnimation == null)
10687         {
10688                 __pFlickAnimation = new (std::nothrow) _FlickAnimation;
10689         }
10690
10691         // Init Flick Animation Config
10692         if (__pFlickAnimation)
10693         {
10694                 float width = 0.0f;
10695                 float height = 0.0f;
10696                 Tizen::Graphics::FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
10697                 Tizen::Graphics::FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
10698                 if (__pEdit->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
10699                 {
10700                         width = portraitSize.width;
10701                         height = portraitSize.height;
10702                 }
10703                 else
10704                 {
10705                         width = landscapeSize.width;
10706                         height = landscapeSize.height;
10707                 }
10708
10709                 __pFlickAnimation->SetSizeInformation(width, height, DEVICE_SIZE_HORIZONTAL, DEVICE_SIZE_VERTICAL);
10710                 __pFlickAnimation->SetSensitivity(FLICK_ANIMATION_FPS_PANEL, FLICK_ANIMATION_SENSITIVITY_PANEL);
10711         }
10712
10713         // Stop Timer
10714         StopFlickTimer();
10715
10716         // Create Timer
10717         if (__pFlickAnimationTimer == null)
10718         {
10719                 __pFlickAnimationTimer = new (std::nothrow) Timer;
10720                 if (__pFlickAnimationTimer == null)
10721                 {
10722                         r = E_OUT_OF_MEMORY;
10723                         goto CATCH;
10724                 }
10725
10726                 r = __pFlickAnimationTimer->Construct(*this);
10727                 if (IsFailed(r))
10728                 {
10729                         delete __pFlickAnimationTimer;
10730                         goto CATCH;
10731                 }
10732         }
10733
10734         return r;
10735
10736 CATCH:
10737         return r;
10738 }
10739
10740 result
10741 _EditPresenter::StartFlickAnimation(const FloatPoint& flickPosition, int flickTime)
10742 {
10743         // delete Scroll Fadeout Timer
10744         if (!__pScrollBar)
10745         {
10746                 return E_SUCCESS;
10747         }
10748
10749         if (__textObjectBounds.height >= __pTextObject->GetTotalHeightF())
10750         {
10751                  return E_SUCCESS;
10752         }
10753
10754         if (InitializeFlickAnimation() != E_SUCCESS)
10755         {
10756                 return E_SYSTEM;
10757         }
10758
10759         //We must check the flick animation about float conversion work at later
10760
10761         // Initialize flick animation
10762         int velocityX = 0;
10763         int velocityY = 0;
10764
10765         __pFlickAnimation->CalculateInitializeVelocity(_CoordinateSystemUtils::ConvertToInteger(flickPosition.x), _CoordinateSystemUtils::ConvertToInteger(flickPosition.y), flickTime, &velocityX, &velocityY);
10766
10767         if (Math::Abs(flickPosition.x) > Math::Abs(flickPosition.y))
10768         {
10769                 __pFlickAnimation->InitializeFlickAmount(velocityX);
10770         }
10771         else
10772         {
10773                 __pFlickAnimation->InitializeFlickAmount(velocityY);
10774         }
10775
10776         return StartFlickTimer(velocityY, velocityX);
10777 }
10778
10779 result
10780 _EditPresenter::StartFlickTimer(int flickVelocityX, int flickVelocityY)
10781 {
10782         if (__pFlickAnimation)
10783         {
10784                 if (ScrollContentsOnFlick() != E_SUCCESS)
10785                 {
10786                         // Stop Timer
10787                         StopFlickTimer();
10788
10789                         return E_SYSTEM;
10790                 }
10791
10792                 // Operate timer
10793                 if (__pFlickAnimationTimer)
10794                 {
10795                         if (__pFlickAnimationTimer->Start(EDIT_FLICK_SCROLL_TIMER_INTERVAL) != E_SUCCESS)
10796                         {
10797                                 StopFlickTimer();
10798                                 return E_SYSTEM;
10799                         }
10800                 }
10801
10802                 return E_SUCCESS;
10803         }
10804         else
10805         {
10806                 return E_SYSTEM;
10807         }
10808 }
10809
10810 result
10811 _EditPresenter::ScrollContentsOnFlick(void)
10812 {
10813         //We must check the flick animation about float conversion work at later
10814
10815         if (__pFlickAnimation)
10816         {
10817                 int moveAmountX = 0;
10818                 int moveAmountY = 0;
10819                 __pFlickAnimation->CalculateNextMove(&moveAmountX, &moveAmountY);
10820
10821                 // Scroll process
10822                 if (ScrollOnFlick(_CoordinateSystemUtils::ConvertToFloat(-moveAmountY*EDIT_FLICK_SCROLL_MOVE_AMOUNT_MULTIPLIER)))
10823                 {
10824                         DrawText();
10825                         DrawScrollBar();
10826                         return E_SUCCESS;
10827                 }
10828         }
10829
10830         return E_SYSTEM;
10831 }
10832
10833 bool
10834 _EditPresenter::ScrollOnFlick(float moveDistanceY)
10835 {
10836         if (moveDistanceY == 0)
10837         {
10838                 FadeOutScrollBar();
10839                 return false;
10840         }
10841
10842         if (!__pScrollBar->GetScrollVisibility())
10843         {
10844                 __pScrollBar->SetScrollVisibility(true);
10845         }
10846
10847         ScrollContents(moveDistanceY);
10848
10849         return true;
10850 }
10851
10852 void
10853 _EditPresenter::SetCursorEnabled(bool enable)
10854 {
10855         __isCursorOpaque = enable;
10856
10857         return;
10858 }
10859
10860 bool
10861 _EditPresenter::IsCursorEnabled(void) const
10862 {
10863         return __isCursorOpaque;
10864 }
10865
10866 void
10867 _EditPresenter::StopFlickTimer(void)
10868 {
10869         if (__pFlickAnimationTimer != null)
10870         {
10871                 __pFlickAnimationTimer->Cancel();
10872                 delete __pFlickAnimationTimer;
10873                 __pFlickAnimationTimer = null;
10874         }
10875
10876         return;
10877 }
10878
10879 result
10880 _EditPresenter::OnFlickTimerExpired(void)
10881 {
10882         result r = E_SUCCESS;
10883
10884         if (__pFlickAnimationTimer)
10885         {
10886                 // Start Timer
10887                 if (__pFlickAnimationTimer->Start(EDIT_FLICK_SCROLL_TIMER_INTERVAL) != E_SUCCESS)
10888                 {
10889                         StopFlickTimer();
10890                         return E_SYSTEM;
10891                 }
10892
10893                 // Scroll DRAW
10894                 if (ScrollContentsOnFlick() != E_SUCCESS)
10895                 {
10896                         StopFlickTimer();
10897
10898                         // Fade Out
10899                         FadeOutScrollBar();
10900                 }
10901
10902                 r = E_SUCCESS;
10903         }
10904         else
10905         {
10906                 r = E_SYSTEM;
10907         }
10908
10909         return r;
10910 }
10911
10912 void
10913 _EditPresenter::SetScrollBarVisible(bool enable)
10914 {
10915         __isScrollBarVisible = enable;
10916
10917         return;
10918 }
10919
10920 void
10921 _EditPresenter::SetScrollBarBounds(const FloatRectangle& bounds)
10922 {
10923         __scrollBarBounds = bounds;
10924
10925         return;
10926 }
10927
10928 FloatRectangle
10929 _EditPresenter::GetDisplayScrollBoundsF(void) const
10930 {
10931         return __scrollBarBounds;
10932 }
10933
10934 FloatRectangle
10935 _EditPresenter::GetInitialBoundsF(void) const
10936 {
10937         return __initialBounds;
10938 }
10939
10940 void
10941 _EditPresenter::SetPreviousScrollBarPosition(int position)
10942 {
10943         __previousScrollBarPos = _CoordinateSystemUtils::ConvertToFloat(position);
10944
10945         return;
10946 }
10947
10948 void
10949 _EditPresenter::SetPreviousScrollBarPosition(float position)
10950 {
10951         __previousScrollBarPos = position;
10952
10953         return;
10954 }
10955
10956 int
10957 _EditPresenter::GetPreviousScrollPosition(void) const
10958 {
10959         return _CoordinateSystemUtils::ConvertToInteger(__previousScrollBarPos);
10960 }
10961
10962 float
10963 _EditPresenter::GetPreviousScrollPositionF(void) const
10964 {
10965         return __previousScrollBarPos;
10966 }
10967
10968 void
10969 _EditPresenter::SetMaximumPreviousScrollBarPosition(int position)
10970 {
10971         __previousScrollBarMaxPos = _CoordinateSystemUtils::ConvertToFloat(position);
10972
10973         return;
10974 }
10975
10976 void
10977 _EditPresenter::SetMaximumPreviousScrollBarPosition(float position)
10978 {
10979         __previousScrollBarMaxPos = position;
10980
10981         return;
10982 }
10983
10984 _Scroll*
10985 _EditPresenter::GetScrollBar(void) const
10986 {
10987         return __pScrollBar;
10988 }
10989
10990 TextObject*
10991 _EditPresenter::GetTextObject(void) const
10992 {
10993         return __pTextObject;
10994 }
10995
10996 void
10997 _EditPresenter::SetAutoShrinkModeEnabled(bool enable)
10998 {
10999         __isAutoShrinkEnabled = enable;
11000
11001         return;
11002 }
11003
11004 bool
11005 _EditPresenter::IsAutoShrinkModeEnabled(void) const
11006 {
11007         return __isAutoShrinkEnabled;
11008 }
11009
11010 _Edit*
11011 _EditPresenter::GetEditView(void) const
11012 {
11013         return __pEdit;
11014 }
11015
11016 void
11017 _EditPresenter::InitializeParentPanel(void)
11018 {
11019         if (__pParentPanel == null)
11020         {
11021                 _ScrollPanel* pScrollPanel = null;
11022                 _Control* pControlCore = null;
11023
11024                 for (pControlCore = __pEdit->GetParent(); pScrollPanel == null; pControlCore = pControlCore->GetParent())
11025                 {
11026                         if (pControlCore == null)
11027                         {
11028                                 return;
11029                         }
11030
11031                         pScrollPanel = dynamic_cast<_ScrollPanel*>(pControlCore);
11032                         if (pScrollPanel)
11033                         {
11034                                 __pParentPanel = pScrollPanel;
11035                                 __pParentPanel->AddScrollEventListener(*__pEdit);
11036                                 break;
11037                         }
11038                 }
11039         }
11040
11041         return;
11042 }
11043
11044 void
11045 _EditPresenter::ScrollPanelToTop(bool show)
11046 {
11047         if (!__pParentPanel)
11048                 return;
11049
11050         FloatRectangle editAbsoluteBounds = __pEdit->GetAbsoluteBoundsF(true);
11051         FloatRectangle panelAbsoluteBounds = __pParentPanel->GetAbsoluteBoundsF(true);
11052         float scrollPosition = __pParentPanel->GetScrollPosition() + (editAbsoluteBounds.y - panelAbsoluteBounds.y);
11053
11054         __pParentPanel->SetScrollPosition(scrollPosition);
11055
11056         if (show)
11057         {
11058                 __pParentPanel->Invalidate();
11059         }
11060
11061         return;
11062 }
11063
11064 void
11065 _EditPresenter::ScrollPanelToCursorPosition(bool show)
11066 {
11067         if (!__pParentPanel)
11068                 return;
11069
11070         result r = E_SUCCESS;
11071
11072         UpdateComponentInformation();
11073
11074         FloatRectangle absCursorBounds(0.0f, 0.0f, 0.0f, 0.0f);
11075         r = CalculateAbsoluteCursorBounds(__cursorPos, absCursorBounds);
11076
11077         if (r != E_SUCCESS)
11078         {
11079                 return;
11080         }
11081
11082         //SysLog(NID_UI_CTRL, "------------------------ScrollPosition recalculation starts~!!!!--------------------------.");
11083
11084         FloatRectangle absPanelRect = __pParentPanel->GetAbsoluteBoundsF(true);
11085         FloatRectangle absEditRect = __pEdit->GetAbsoluteBoundsF(true);
11086
11087         float scrollPosition = __pParentPanel->GetScrollPosition();
11088         float upSideGap = 0.0f;
11089         float newScrollPosition = 0.0f;
11090
11091         if (__textObjectBounds.height < absCursorBounds.height)
11092         {
11093                 absCursorBounds.height = __textObjectBounds.height;
11094         }
11095
11096         upSideGap = absPanelRect.y - absCursorBounds.y; // absPanelRect.y value is always positive
11097
11098         if (upSideGap > 0.0f)
11099         {
11100                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
11101                 {
11102                         newScrollPosition = scrollPosition -(absPanelRect.y -absEditRect.y);
11103                         //SysLog(NID_UI_CTRL, "[single line edit] Move up till top boundary of edit.");
11104                 }
11105                 else
11106                 {
11107                         newScrollPosition = scrollPosition -(absPanelRect.y -absCursorBounds.y);
11108                         //SysLog(NID_UI_CTRL, "[multi-line edit] Move up till up position of cursor.");
11109                 }
11110
11111                 //SysLog(NID_UI_CTRL, "move up scroll position from %f to %f", scrollPosition, newScrollPosition);
11112         }
11113         else
11114         {
11115                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
11116                 {
11117                         if ((absPanelRect.y + absPanelRect.height) > (absEditRect.y + absEditRect.height))
11118                         {
11119                                 //SysLog(NID_UI_CTRL, "[single line edit] already exists in exposed region.");
11120
11121                                 return;
11122                         }
11123
11124                         newScrollPosition = scrollPosition + ((absEditRect.y + absEditRect.height) -(absPanelRect.y + absPanelRect.height));
11125                         SysLog(NID_UI_CTRL, "Move down till down boundary of edit.");
11126                 }
11127                 else
11128                 {
11129                         if ((absCursorBounds.y + absCursorBounds.height) < (absPanelRect.y + absPanelRect.height))
11130                         {
11131                                 //SysLog(NID_UI_CTRL, "[multi-line edit]Cursor already exist in exposed region.");
11132
11133                                 return;
11134                         }
11135
11136                         newScrollPosition = scrollPosition + ((absCursorBounds.y + absCursorBounds.height) -(absPanelRect.y + absPanelRect.height));
11137                         //SysLog(NID_UI_CTRL, "Move down till down position of cursor.");
11138                 }
11139
11140                 //SysLog(NID_UI_CTRL, "move down scroll position from %f to %f", scrollPosition, newScrollPosition);
11141         }
11142
11143         __pParentPanel->SetScrollPosition(newScrollPosition);
11144         __pParentPanel->Invalidate();
11145
11146         //SysLog(NID_UI_CTRL, "------------------------ScrollPosition recalculation Ends!!!!--------------------------.");
11147         return;
11148 }
11149
11150 void
11151 _EditPresenter::SetSearchBarFlag(bool enabled)
11152 {
11153         __isSearchBar = enabled;
11154
11155         return;
11156 }
11157
11158 bool
11159 _EditPresenter::GetSearchBarFlag(void) const
11160 {
11161         return __isSearchBar;
11162 }
11163
11164 result
11165 _EditPresenter::SetFocused(void)
11166 {
11167         bool focused = true;
11168         if (__pParentPanel)
11169         {
11170                 _Window* pTop = __pParentPanel->GetRootWindow();
11171                 if (pTop)
11172                 {
11173                         if ((pTop->GetFocusControl(__pEdit) != __pEdit) && __pEdit->IsFocused() == false)
11174                         {
11175                                 focused = false;
11176                         }
11177                 }
11178         }
11179         else if (__pEdit->IsFocused() == false)
11180         {
11181                 focused = false;
11182         }
11183
11184         if (focused == false)
11185         {
11186                 __pEdit->SetFocused();
11187         }
11188
11189         return E_SUCCESS;
11190 }
11191
11192 void
11193 _EditPresenter::GetWordPosition(int cursorPos, int& startPos, int& endPos) const
11194 {
11195         int textLength = GetTextLength();
11196         bool isDetected = false;
11197
11198         if (cursorPos >= textLength && cursorPos > 0)
11199         {
11200                 cursorPos--;
11201         }
11202         else
11203         {
11204                 if (IsDelimiter(__pTextBuffer[cursorPos]) && cursorPos > 0)
11205                 {
11206                         cursorPos--;
11207                 }
11208         }
11209
11210         for (int i = cursorPos; i >= 0; i--)
11211         {
11212                 if (IsDelimiter(__pTextBuffer[i]))
11213                 {
11214                         startPos = i + 1;
11215                         isDetected = true;
11216                         break;
11217                 }
11218         }
11219
11220         if (isDetected == false)
11221         {
11222                 startPos = 0;
11223         }
11224         else
11225         {
11226                 isDetected = false;
11227         }
11228
11229         for (int i = cursorPos; i < textLength; i++)
11230         {
11231                 if (IsDelimiter(__pTextBuffer[i]))
11232                 {
11233                         endPos = i;
11234                         isDetected = true;
11235                         break;
11236                 }
11237         }
11238
11239         if (isDetected == false)
11240         {
11241                 endPos = textLength;
11242         }
11243
11244         if (startPos > endPos)
11245         {
11246                 int temp = startPos;
11247                 startPos = endPos;
11248                 endPos = temp;
11249         }
11250         return;
11251 }
11252
11253 result
11254 _EditPresenter::GetTextImageRangeAt(int postion, int& startPosition, int& endPosition) const
11255 {
11256         int length = GetTextLength();
11257         startPosition = -1;
11258         endPosition = -1;
11259
11260         SysTryReturnResult(NID_UI_CTRL, postion >= 0 && postion <= length, E_OUT_OF_RANGE, "The given index is out-of-range.");
11261
11262         _Text::TextElement* pTextElement = __pTextObject->GetElementAtTextIndex(postion);
11263         const TextSimple* pSimpleText = dynamic_cast <const TextSimple*>(pTextElement);
11264         if (pSimpleText != null && pSimpleText->GetBitmap() != null)
11265         {
11266                 startPosition = pSimpleText->GetTextOffset();
11267                 endPosition = startPosition + pSimpleText->GetTextLength();
11268                 return E_SUCCESS;
11269         }
11270
11271         return E_OBJ_NOT_FOUND;
11272 }
11273
11274 bool
11275 _EditPresenter::IsDelimiter(wchar_t character) const
11276 {
11277         bool ret = false;
11278
11279         switch (character)
11280         {
11281         case 0x0A: // NLine Feed
11282                 ret = true;
11283                 break;
11284         case 0x0D: // Carriage Return
11285                 ret = true;
11286                 break;
11287         case 0x20: // Space
11288                 ret = true;
11289                 break;
11290         default:
11291                 break;
11292         }
11293
11294         return ret;
11295 }
11296
11297 void
11298 _EditPresenter::InitializeCopyPasteManager(void)
11299 {
11300         bool releaseBlock = true;
11301
11302         if (__pCopyPasteManager)
11303         {
11304                 releaseBlock = __pCopyPasteManager->GetTextBlockReleaseFlag();
11305                 delete __pCopyPasteManager;
11306                 __pCopyPasteManager = null;
11307         }
11308
11309         if (IsBlocked() == true && releaseBlock)
11310         {
11311                 ReleaseTextBlock();
11312                 __pEdit->Invalidate();
11313         }
11314
11315         __isCopyPasteManagerExist = false;
11316         __isCopyPastePopupMoving = false;
11317
11318         return;
11319 }
11320
11321 bool
11322 _EditPresenter::IsCopyPasteManagerExist(void) const
11323 {
11324         return __isCopyPasteManagerExist;
11325 }
11326
11327 FloatRectangle
11328 _EditPresenter::GetTextAreaBoundsF(void) const
11329 {
11330         return __textObjectBounds;
11331 }
11332
11333 FloatRectangle
11334 _EditPresenter::GetTitleBoundsF(void) const
11335 {
11336         return __titleBounds;
11337 }
11338
11339 FloatRectangle
11340 _EditPresenter::GetClearIconBoundsF(void) const
11341 {
11342         return __clearIconBounds;
11343 }
11344
11345 void
11346 _EditPresenter::FinishTextComposition(void)
11347 {
11348         if (__isInputConnectionBound && __isTextComposing)
11349         {
11350                 __pEdit->SetTextEventEnabled(false);
11351                 __pInputConnection->FinishTextComposition();
11352                 __isTextComposing = false;
11353                 __composingTextLength = 0;
11354                 __pEdit->SetTextEventEnabled(true);
11355         }
11356
11357         return;
11358 }
11359
11360 bool
11361 _EditPresenter::GetTextCompositionState(void) const
11362 {
11363         return __isTextComposing;
11364 }
11365
11366 bool
11367 _EditPresenter::IsCopyPastePopup(const _Control& control) const
11368 {
11369         if (__pCopyPasteManager)
11370         {
11371                 return __pCopyPasteManager->IsCopyPastePopup(control);
11372         }
11373
11374         return false;
11375 }
11376
11377 bool
11378 _EditPresenter::IsCopyPasteHandle(const _Control& control) const
11379 {
11380         if (__pCopyPasteManager)
11381         {
11382                 return __pCopyPasteManager->IsCopyPasteHandle(control);
11383         }
11384
11385         return false;
11386 }
11387
11388 void
11389 _EditPresenter::SetCursorChangedFlag(bool enabled)
11390 {
11391         __isCursorChanged = enabled;
11392
11393         return;
11394 }
11395
11396 bool
11397 _EditPresenter::GetCursorChangedFlag(void) const
11398 {
11399         return __isCursorChanged;
11400 }
11401
11402 void
11403 _EditPresenter::SetEditGroupStyle(GroupStyle groupStyle)
11404 {
11405         __groupStyle = groupStyle;
11406
11407         return;
11408 }
11409
11410 void
11411 _EditPresenter::PostInternalEvent(const Tizen::Base::String& type)
11412 {
11413         ClearLastResult();
11414
11415         ArrayList* pArgs = new (std::nothrow) ArrayList();
11416         SysTryReturnVoidResult(NID_UI_CTRL, pArgs != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
11417
11418         result r = E_SYSTEM;
11419         r = pArgs->Construct();
11420         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Unable to construct pArgs");
11421
11422         String* pType = new (std::nothrow) String(type);
11423         SysTryReturnVoidResult(NID_UI, pType, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
11424
11425         r = pArgs->Add(*pType);
11426         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Unable to add type to pArgs");
11427
11428         _UiNotificationEvent event(__pEdit->GetHandle(), pArgs);
11429         r = _UiEventManager::GetInstance()->PostEvent(event);
11430         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Unable to send event");
11431
11432         return;
11433 }
11434
11435 void
11436 _EditPresenter::ReleaseCopyPastePopup(void)
11437 {
11438         if (__pCopyPasteManager)
11439         {
11440                 return __pCopyPasteManager->ReleaseCopyPastePopup();
11441         }
11442 }
11443
11444 bool
11445 _EditPresenter::IsCopyPastePopupExist(void) const
11446 {
11447         if (__pCopyPasteManager)
11448         {
11449                 if (__pCopyPasteManager->GetCopyPastePopup())
11450                 {
11451                         return true;
11452                 }
11453                 else
11454                 {
11455                         return false;
11456                 }
11457         }
11458         return false;
11459 }
11460
11461 bool
11462 _EditPresenter::IsCopyPasteHandleExist(void) const
11463 {
11464         if (__pCopyPasteManager)
11465         {
11466                 return __pCopyPasteManager->IsCopyPasteHandleExist();
11467         }
11468         return false;
11469 }
11470
11471 bool
11472 _EditPresenter::IsUnsupportedChracterExist(const KeypadStyle keypadStyle, const Tizen::Base::String& text)
11473 {
11474         const int numberOfCharOnNumOnlyStyle = 10;
11475         const int numberOfCharOnPhoneNumStyle = 14;
11476         const int numberOfCharOnIpStyle = 18;
11477
11478         const wchar_t* TempKey = null;
11479         const wchar_t characterOnNumOnlyStyle[numberOfCharOnNumOnlyStyle+1] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/, 0};
11480         const wchar_t characterOnPhoneNumStyle[numberOfCharOnPhoneNumStyle+1] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/,
11481                                                                         0x2a/***/, 0x2b/*+*/, 0x23/*#*/, 0x70/*p*/, 0};
11482         const wchar_t characterOnIPStyle[numberOfCharOnIpStyle+1] = { 0x30/*0*/, 0x31/*1*/, 0x32/*2*/, 0x33/*3*/, 0x34/*4*/, 0x35/*5*/, 0x36/*6*/, 0x37/*7*/, 0x38/*8*/, 0x39/*9*/,
11483                                                                         0x3a/*:*/, 0x2e/*.*/, 0x61/*a*/, 0x62/*b*/, 0x63/*c*/, 0x64/*d*/, 0x65/*e*/, 0x66/*f*/, 0};
11484         bool isSupportedCharacterExist = false;
11485         int supportedCharacterCount = 0;
11486
11487         switch (keypadStyle)
11488         {
11489         case KEYPAD_STYLE_NUMBER:
11490                 supportedCharacterCount = numberOfCharOnNumOnlyStyle;
11491                 TempKey = characterOnNumOnlyStyle;
11492                 break;
11493         case KEYPAD_STYLE_PHONE_NUMBER:
11494                 supportedCharacterCount = numberOfCharOnPhoneNumStyle;
11495                 TempKey = characterOnPhoneNumStyle;
11496                 break;
11497         case KEYPAD_STYLE_IP_V4:
11498                 supportedCharacterCount = numberOfCharOnIpStyle;
11499                 TempKey = characterOnIPStyle;
11500                 break;
11501         default:
11502                 return false;
11503         }
11504
11505         if (text.GetLength() < 1)
11506         {
11507                 return false;
11508         }
11509
11510         for (int i = 0; i < text.GetLength(); i++)
11511         {
11512                 isSupportedCharacterExist = false;
11513                 wchar_t checkChar =0;
11514                 if (text.GetCharAt(i, checkChar) != E_SUCCESS)
11515                 {
11516                         break;
11517                 }
11518                 for (int j = 0; j < supportedCharacterCount ; j++)
11519                 {
11520                         if (TempKey[j] == checkChar)
11521                         {
11522                                 isSupportedCharacterExist = true;
11523                                 break;
11524                         }
11525                 }
11526                 if (!isSupportedCharacterExist)
11527                 {
11528                         return true;
11529                 }
11530         }
11531
11532         return false;
11533 }
11534
11535 void
11536 _EditPresenter::SetBlockRangeWithShiftArrowkey(_KeyCode keyCode)
11537 {
11538         int start = 0;
11539         int end = 0;
11540         if (IsBlocked() == true)
11541         {
11542                 GetBlockRange(start, end);
11543                 switch(keyCode)
11544                 {
11545                         case _KEY_LEFT:
11546                                 if (__textBlockMoveLeft)
11547                                 {
11548                                         if (start > 0)
11549                                         {
11550                                                 SetBlockRange(--start, end);
11551                                         }
11552                                 }
11553                                 else
11554                                 {
11555                                         if (start < end - 1)
11556                                         {
11557                                                 SetBlockRange(start, --end);
11558                                         }
11559                                         else if (start == end - 1)
11560                                         {
11561                                                 ReleaseTextBlock();
11562                                                 SetCursorPosition(start);
11563                                         }
11564                                 }
11565                                 break;
11566                         case _KEY_UP:
11567                                 if (__textBlockMoveLeft)
11568                                 {
11569                                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(start);
11570
11571                                         if (curCursorLine > 0)
11572                                         {
11573                                                 int offset = start - __pTextObject->GetFirstTextIndexAt(curCursorLine);
11574                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine-1);
11575                                                 start = offset + firstTextIndex;
11576                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine-1);
11577                                                 if (offset > textLength)
11578                                                 {
11579                                                         start = firstTextIndex+textLength-1;
11580                                                 }
11581                                                 SetBlockRange(start, end);
11582                                         }
11583                                 }
11584                                 else
11585                                 {
11586                                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(end);
11587
11588                                         if (curCursorLine > 0)
11589                                         {
11590                                                 int offset = end - __pTextObject->GetFirstTextIndexAt(curCursorLine);
11591                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine-1);
11592                                                 end = offset + firstTextIndex;
11593                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine-1);
11594                                                 if (offset > textLength)
11595                                                 {
11596                                                         end = firstTextIndex+textLength;
11597                                                 }
11598                                                 if (start > end)
11599                                                 {
11600                                                         int temp = start;
11601                                                         start  = end;
11602                                                         end = temp;
11603                                                         __textBlockMoveLeft = true;
11604                                                         SetBlockRange(start, end);
11605                                                 }
11606                                                 else if (start == end)
11607                                                 {
11608                                                         ReleaseTextBlock();
11609                                                         SetCursorPosition(end);
11610                                                 }
11611                                                 else
11612                                                 {
11613                                                         SetBlockRange(start, end);
11614                                                 }
11615                                         }
11616                                 }
11617                                 break;
11618                         case _KEY_DOWN:
11619                                 if (__textBlockMoveLeft)
11620                                 {
11621                                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(start);
11622                                         int totalLine = __pTextObject->GetTotalLineCount();
11623                                         if (curCursorLine < totalLine - 1)
11624                                         {
11625                                                 int offset = start - __pTextObject->GetFirstTextIndexAt(curCursorLine);
11626                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine+1);
11627                                                 start = offset + firstTextIndex;
11628                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine+1);
11629                                                 if (offset > textLength)
11630                                                 {
11631                                                         start = firstTextIndex+textLength;
11632                                                 }
11633
11634                                                 if (start > end)
11635                                                 {
11636                                                         int temp = start;
11637                                                         start  = end;
11638                                                         end = temp;
11639                                                         __textBlockMoveLeft = false;
11640                                                         SetBlockRange(start, end);
11641                                                 }
11642                                                 else if (start == end)
11643                                                 {
11644                                                         ReleaseTextBlock();
11645                                                         SetCursorPosition(end);
11646                                                 }
11647                                                 else
11648                                                 {
11649                                                         SetBlockRange(start, end);
11650                                                 }
11651                                         }
11652                                 }
11653                                 else
11654                                 {
11655                                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(end);
11656                                         int totalLine = __pTextObject->GetTotalLineCount();
11657                                         if (curCursorLine < totalLine - 1)
11658                                         {
11659                                                 int offset = end - __pTextObject->GetFirstTextIndexAt(curCursorLine);
11660                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine+1);
11661                                                 end = offset + firstTextIndex;
11662                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine+1);
11663                                                 if (offset > textLength)
11664                                                 {
11665                                                         end = firstTextIndex+textLength;
11666                                                 }
11667                                                 SetBlockRange(start, end);
11668                                         }
11669                                 }
11670                                 break;
11671                         case _KEY_RIGHT:
11672                                 if (__textBlockMoveLeft)
11673                                 {
11674                                         if (start + 1 < end)
11675                                         {
11676                                                 SetBlockRange(++start, end);
11677                                         }
11678                                         else if (start + 1 == end)
11679                                         {
11680                                                 ReleaseTextBlock();
11681                                                 SetCursorPosition(end);
11682                                         }
11683                                 }
11684                                 else
11685                                 {
11686                                         if (end + 1 <= GetTextLength())
11687                                         {
11688                                                 SetBlockRange(start, ++end);
11689                                         }
11690                                 }
11691                                 break;
11692                         default:
11693                                 break;
11694                 }
11695
11696                 if (IsBlocked())
11697                 {
11698                         if (__textBlockMoveLeft)
11699                         {
11700                                 __pTextObject->SetFirstDisplayLineIndexFromTextIndex(start);
11701                         }
11702                         SetCursorChangedFlag(!__textBlockMoveLeft);
11703                 }
11704                 DrawText();
11705         }
11706         else
11707         {
11708                 switch(keyCode)
11709                 {
11710                         case _KEY_LEFT:
11711                                 if (__cursorPos > 0)
11712                                 {
11713                                         start = __cursorPos - 1;
11714                                         end = __cursorPos;
11715                                         SetBlockRange(start, end);
11716                                         __textBlockMoveLeft = true;
11717                                 }
11718                                 break;
11719                         case _KEY_UP:
11720                                 {
11721                                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
11722
11723                                         if (curCursorLine > 0)
11724                                         {
11725                                                 int offset = __cursorPos - __pTextObject->GetFirstTextIndexAt(curCursorLine);
11726                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine-1);
11727                                                 start = offset + firstTextIndex;
11728                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine-1);
11729                                                 if (offset > textLength)
11730                                                 {
11731                                                         start = firstTextIndex+textLength -1;
11732                                                 }
11733                                                 end = __cursorPos;
11734                                                 SetBlockRange(start, end);
11735                                                 __textBlockMoveLeft = true;
11736                                         }
11737                                 }
11738                                 break;
11739                         case _KEY_DOWN:
11740                                 if (GetTextLength() >= __cursorPos + 1)
11741                                 {
11742                                         int curCursorLine = __pTextObject->GetLineIndexAtTextIndex(__pTextObject->GetCursorIndex());
11743                                         int totalLine = __pTextObject->GetTotalLineCount();
11744                                         if (curCursorLine < totalLine - 1)
11745                                         {
11746                                                 int offset = __cursorPos - __pTextObject->GetFirstTextIndexAt(curCursorLine);
11747                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine+1);
11748                                                 end = offset + firstTextIndex;
11749                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine+1);
11750                                                 if (offset > textLength)
11751                                                 {
11752                                                         end = firstTextIndex+textLength;
11753                                                 }
11754                                         }
11755                                         else if (curCursorLine == totalLine - 1)
11756                                         {
11757                                                 int firstTextIndex = __pTextObject->GetFirstTextIndexAt(curCursorLine);
11758                                                 int textLength = __pTextObject->GetTextLengthAt(curCursorLine);
11759                                                 end = firstTextIndex + textLength;
11760                                         }
11761                                         start = __cursorPos;
11762                                         SetBlockRange(start, end);
11763                                         __textBlockMoveLeft = false;
11764                                 }
11765                                 break;
11766                         case _KEY_RIGHT:
11767                                 if (GetTextLength() >= __cursorPos + 1)
11768                                 {
11769                                         start = __cursorPos;
11770                                         end = __cursorPos + 1;
11771                                         SetBlockRange(start, end);
11772                                         __textBlockMoveLeft = false;
11773                                 }
11774                                 break;
11775                         default:
11776                                 break;
11777                 }
11778                 DrawText();
11779         }
11780         if (IsBlocked())
11781         {
11782                 __textBlockMoving = true;
11783         }
11784 }
11785
11786 void
11787 _EditPresenter::SetBlockRangeWithCtrlShiftArrowkey(_KeyCode keyCode)
11788 {
11789         int start = 0;
11790         int end = 0;
11791         int originalStart = 0;
11792         int originalEnd = 0;
11793         if (IsBlocked() == true)
11794         {
11795                 GetBlockRange(start, end);
11796                 switch(keyCode)
11797                 {
11798                         case _KEY_LEFT:
11799                                 if (__textBlockMoveLeft)
11800                                 {
11801                                         if (start > 0)
11802                                         {
11803                                                 originalStart = start;
11804                                                 originalEnd = end;
11805                                                 GetWordPosition(start-1, start, end);
11806                                                 SetBlockRange(start, originalEnd);
11807                                         }
11808                                 }
11809                                 else
11810                                 {
11811                                         originalStart = start;
11812                                         originalEnd = end;
11813                                         GetWordPosition(end, start, end);
11814                                         if (originalEnd == start)
11815                                         {
11816                                                 GetWordPosition(start-1, start, end);
11817                                         }
11818
11819                                         if (originalStart < start)
11820                                         {
11821                                                 SetBlockRange(originalStart, start);
11822                                         }
11823                                         else if (originalStart > start)
11824                                         {
11825                                                 SetBlockRange(start, originalStart);
11826                                                 __textBlockMoveLeft = true;
11827                                         }
11828                                         else if (originalStart == start)
11829                                         {
11830                                                 ReleaseTextBlock();
11831                                                 SetCursorPosition(start);
11832                                                 __textBlockMoveLeft = true;
11833                                         }
11834                                 }
11835                                 break;
11836                         case _KEY_RIGHT:
11837                                 if (__textBlockMoveLeft)
11838                                 {
11839                                         originalStart = start;
11840                                         originalEnd = end;
11841                                         GetWordPosition(start, start, end);
11842                                         if (originalStart == end)
11843                                         {
11844                                                 GetWordPosition(end+1, start, end);
11845                                         }
11846                                         if (originalEnd > end)
11847                                         {
11848                                                 SetBlockRange(end, originalEnd);
11849                                         }
11850                                         else if (originalEnd < end)
11851                                         {
11852                                                 SetBlockRange(originalEnd, end);
11853                                                 __textBlockMoveLeft = false;
11854                                         }
11855                                         else if (originalEnd == end)
11856                                         {
11857                                                 ReleaseTextBlock();
11858                                                 SetCursorPosition(end);
11859                                                 __textBlockMoveLeft = false;
11860                                         }
11861                                 }
11862                                 else
11863                                 {
11864                                         if (end < GetTextLength())
11865                                         {
11866                                                 originalStart = start;
11867                                                 originalEnd = end;
11868                                                 GetWordPosition(end+1, start, end);
11869                                                 SetBlockRange(originalStart, end);
11870                                         }
11871                                 }
11872                                 break;
11873                         default:
11874                                 break;
11875                 }
11876
11877                 if (IsBlocked())
11878                 {
11879                         if (__textBlockMoveLeft)
11880                         {
11881                                 __pTextObject->SetFirstDisplayLineIndexFromTextIndex(start);
11882                         }
11883                         SetCursorChangedFlag(!__textBlockMoveLeft);
11884                 }
11885                 DrawText();
11886         }
11887         else
11888         {
11889                 switch(keyCode)
11890                 {
11891                         case _KEY_LEFT:
11892                                 if (__cursorPos > 0)
11893                                 {
11894                                         GetWordPosition(__cursorPos, start, end);
11895                                         if (__cursorPos != start)
11896                                         {
11897                                                 SetBlockRange(start, __cursorPos);
11898                                         }
11899                                         else
11900                                         {
11901                                                 GetWordPosition(start-1, start, end);
11902                                                 SetBlockRange(start, __cursorPos);
11903                                         }
11904                                         __textBlockMoveLeft = true;
11905                                 }
11906                                 break;
11907                         case _KEY_RIGHT:
11908                                 if (GetTextLength() >= __cursorPos + 1)
11909                                 {
11910                                         GetWordPosition(__cursorPos, start, end);
11911                                         if (__cursorPos != end)
11912                                         {
11913                                                 SetBlockRange(__cursorPos, end);
11914                                         }
11915                                         else
11916                                         {
11917                                                 GetWordPosition(end+1, start, end);
11918                                                 SetBlockRange(__cursorPos, end);
11919                                         }
11920                                         __textBlockMoveLeft = false;
11921                                 }
11922                                 break;
11923                         default:
11924                                 break;
11925                 }
11926                 DrawText();
11927         }
11928         if (IsBlocked())
11929         {
11930                 __textBlockMoving = true;
11931         }
11932 }
11933
11934 void
11935 _EditPresenter::SetEditTextFilter(_IEditTextFilter* pFilter)
11936 {
11937         __pTextFilter = pFilter;
11938
11939         return;
11940 }
11941
11942 bool
11943 _EditPresenter::ValidatePastedText(const String& pastedText, String& replacedText)
11944 {
11945         bool enable = false;
11946         if (__pTextFilter)
11947         {
11948                 enable = __pTextFilter->ValidatePastedText(pastedText, replacedText);
11949         }
11950
11951         return enable;
11952 }
11953
11954 void
11955 _EditPresenter::SendOpaqueCommand (const String& command)
11956 {
11957         if (command.Equals(L"KEYPAD_STYLE: PASSWORD", true))
11958         {
11959                 if (__pInputConnection)
11960                 {
11961                         __pInputConnection->SetPasswordMode(true);
11962                 }
11963                 return;
11964         }
11965         if (__pInputConnection)
11966         {
11967                 __pInputConnection->SendOpaqueCommand(command);
11968         }
11969
11970         return;
11971 }
11972
11973 bool
11974 _EditPresenter::IsBounded(void) const
11975 {
11976         return __isInputConnectionBound;
11977 }
11978
11979 bool
11980 _EditPresenter::AdjustRTLTextAlignment(const _EditTextType textType)
11981 {
11982         result r = E_SUCCESS;
11983
11984         switch (textType)
11985         {
11986         case EDIT_TEXT_TYPE_INPUT:
11987                 if (GetTextAlignment() != ALIGNMENT_LEFT)
11988                 {
11989                         if (_BidiUtils::IsRTL(GetText()) == true)
11990                         {
11991                                 __pTextObject->SetTextBidiHint(TEXT_BIDI_HINT_RTL);
11992                         }
11993                         else
11994                         {
11995                                 __pTextObject->SetTextBidiHint(TEXT_BIDI_HINT_LTR);
11996                         }
11997                         return false;
11998                 }
11999                 if (_BidiUtils::IsRTL(GetText()) == true)
12000                 {
12001                         if (__horizontalAlignmentForBidi == ALIGNMENT_LEFT)
12002                         {
12003                                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
12004                                 {
12005                                         r = __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
12006                                 }
12007                                 else
12008                                 {
12009                                         r = __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT | TEXT_OBJECT_ALIGNMENT_TOP);
12010                                 }
12011                                 __horizontalAlignmentForBidi = ALIGNMENT_RIGHT;
12012                                 __pTextObject->SetTextBidiHint(TEXT_BIDI_HINT_RTL);
12013                                 if (r == E_SUCCESS)
12014                                 {
12015                                         return true;
12016                                 }
12017                         }
12018                 }
12019                 else
12020                 {
12021                         if (__horizontalAlignmentForBidi == ALIGNMENT_RIGHT)
12022                         {
12023                                 if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
12024                                 {
12025                                         r = __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
12026                                 }
12027                                 else
12028                                 {
12029                                         r = __pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_TOP);
12030                                 }
12031                                 __horizontalAlignmentForBidi = ALIGNMENT_LEFT;
12032                                 __pTextObject->SetTextBidiHint(TEXT_BIDI_HINT_LTR);
12033                                 if (r == E_SUCCESS)
12034                                 {
12035                                         return true;
12036                                 }
12037                         }
12038                 }
12039                 break;
12040         case EDIT_TEXT_TYPE_GUIDE:
12041                 if (__pGuideTextObject == null)
12042                 {
12043                         return false;
12044                 }
12045                 if (_BidiUtils::IsRTL(__guideText) == true)
12046                 {
12047                         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
12048                         {
12049                                 r = __pGuideTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
12050                         }
12051                         else
12052                         {
12053                                 r = __pGuideTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT | TEXT_OBJECT_ALIGNMENT_TOP);
12054                         }
12055                         __pGuideTextObject->SetTextBidiHint(TEXT_BIDI_HINT_RTL);
12056                         if (r == E_SUCCESS)
12057                         {
12058                                 return true;
12059                         }
12060                 }
12061                 else
12062                 {
12063                         if (__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE)
12064                         {
12065                                 r = __pGuideTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
12066                         }
12067                         else
12068                         {
12069                                 r = __pGuideTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_TOP);
12070                         }
12071                         __pGuideTextObject->SetTextBidiHint(TEXT_BIDI_HINT_LTR);
12072                         if (r == E_SUCCESS)
12073                         {
12074                                 return true;
12075                         }
12076                 }
12077                 break;
12078         case EDIT_TEXT_TYPE_TITLE:
12079                 if (__pTitleTextObject == null)
12080                 {
12081                         return false;
12082                 }
12083                 if (_BidiUtils::IsRTL(__titleText) == true)
12084                 {
12085                         r = __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_RIGHT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
12086                         if (r == E_SUCCESS)
12087                         {
12088                                 return true;
12089                         }
12090                 }
12091                 else
12092                 {
12093                         r = __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
12094                         if (r == E_SUCCESS)
12095                         {
12096                                 return true;
12097                         }
12098                 }
12099                 break;
12100         default:
12101                 break;
12102         }
12103
12104         return false;
12105 }
12106
12107 void
12108 _EditPresenter::UpdateKeypadCommandString(void)
12109 {
12110         if (!__isKeypadCommandButtonUserSetting)
12111         {
12112                 __pEditModel->UpdateKeypadCommandButtonText();
12113                 if (__pCommandButton)
12114                 {
12115                         _Button* pLeftButton = __pCommandButton->GetItem(COMMAND_BUTTON_POSITION_LEFT);
12116                         if (pLeftButton)
12117                         {
12118                                 pLeftButton->SetText(__pEditModel->GetKeypadCommandButtonText(COMMAND_BUTTON_POSITION_LEFT));
12119                         }
12120                         _Button* pRightButton = __pCommandButton->GetItem(COMMAND_BUTTON_POSITION_RIGHT);
12121                         if (pRightButton)
12122                         {
12123                                 pRightButton->SetText(__pEditModel->GetKeypadCommandButtonText(COMMAND_BUTTON_POSITION_RIGHT));
12124                         }
12125                 }
12126         }
12127 }
12128
12129 result
12130 _EditPresenter::SetPasswordVisible(bool visible)
12131 {
12132         result r = E_SUCCESS;
12133
12134         SysTryReturnResult(NID_UI_CTRL, (__pEdit->GetEditStyle() & EDIT_STYLE_PASSWORD), E_INVALID_OPERATION,
12135                                           "Edit Style is not EDIT_STYLE_PASSWORD.")
12136
12137
12138         if (__isPasswordVisible == visible)
12139         {
12140                 return r;
12141         }
12142
12143         __isPasswordVisible = visible;
12144
12145         if (GetTextLength()== 0)
12146         {
12147                 return r;
12148         }
12149
12150         InitializeCopyPasteManager();
12151
12152         FinishTextComposition();
12153
12154         if (__isPasswordVisible)
12155         {
12156                 StopPasswordTimer();
12157                 ChangePasswordToPlainText();
12158         }
12159         else
12160         {
12161                 ReplaceTextIntoPasswordHyphenString();
12162                 __pTextObject->NotifyTextChanged(__pTextBuffer, 0, __pTextString->GetLength(), 0);
12163         }
12164
12165         return r;
12166 }
12167
12168 bool
12169 _EditPresenter::IsPasswordVisible(void) const
12170 {
12171         return __isPasswordVisible;
12172 }
12173
12174 bool
12175 _EditPresenter::IsClearIconPressed(void) const
12176 {
12177         return __isClearIconPressed;
12178 }
12179
12180 result
12181 _EditPresenter::DrawFocusRing(Tizen::Graphics::Canvas& canvas)
12182 {
12183         if (__pEditModel->IsViewModeEnabled() || !__pEdit->IsEnabled())
12184         {
12185                 return E_SUCCESS;
12186         }
12187
12188         result r = E_SUCCESS;
12189         Bitmap* pFocusRing = null;
12190         Color color = __pEdit->GetColor(EDIT_STATUS_HIGHLIGHTED);
12191
12192         if (IsCurrentFocused() && color.GetAlpha())
12193         {
12194                 Color focusColor;
12195                 GET_COLOR_CONFIG(FOCUSUI::CONTENT_BG_HIGHLIGHTED, focusColor);
12196                 focusColor.SetAlpha(color.GetAlpha());
12197
12198                 r = GET_BITMAP_CONFIG_N(EDIT::BG_RING_FOCUSED, BITMAP_PIXEL_FORMAT_ARGB8888, pFocusRing);
12199                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
12200
12201                 FloatRectangle editRect(0.0f, 0.0f, __pEdit->GetBoundsF().width, __pEdit->GetBoundsF().height);
12202
12203                 Bitmap* pReplacementFocusRing = _BitmapImpl::GetColorReplacedBitmapN(*pFocusRing, Color::GetColor(COLOR_ID_MAGENTA), focusColor);
12204                 SysTryCatch(NID_UI_CTRL, pReplacementFocusRing, , r = GetLastResult(), "Unable to allocate text buffer.");
12205
12206                 if (pReplacementFocusRing)
12207                 {
12208                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementFocusRing))
12209                         {
12210                                 canvas.DrawNinePatchedBitmap(editRect, *pReplacementFocusRing);
12211                         }
12212                 }
12213                 delete pFocusRing;
12214                 delete pReplacementFocusRing;
12215         }
12216
12217         return r;
12218
12219 CATCH:
12220         delete pFocusRing;
12221
12222         return r;
12223 }
12224
12225 void
12226 _EditPresenter::OnScrollPositionChanged(Tizen::Ui::_Control& source, float scrollPosition)
12227 {
12228         if (__isCopyPasteManagerExist)
12229         {
12230                 __pCopyPasteManager->Show();
12231         }
12232 }
12233
12234 void
12235 _EditPresenter::OnScrollStopped(Tizen::Ui::_Control& source)
12236 {
12237         if (__pCopyPasteManager)
12238         {
12239                 if (__needToCreateCopyPastePopup && !__pCopyPasteManager->GetCopyPastePopup())
12240                 {
12241                         __pCopyPasteManager->CreateCopyPastePopup();
12242                         if (__pCopyPasteManager->GetCopyPastePopup())
12243                         {
12244                                 __needToCreateCopyPastePopup = false;
12245                         }
12246                 }
12247                 __pCopyPasteManager->Show();
12248         }
12249 }
12250
12251 _Window*
12252 _EditPresenter::OnDragAndDropBeginning(void)
12253 {
12254         SysLog(NID_UI_CTRL, "Drag & Drop Callback is called");
12255
12256         result r = E_SUCCESS;
12257         _Label* pLabel = null;
12258         FloatDimension dragWindowDimension;
12259         _ControlOrientation orientation = __pEdit->GetOrientation();
12260
12261         GET_SHAPE_CONFIG(EDIT::DRAG_AND_DROP_WINDOW_WIDTH, orientation, dragWindowDimension.width);
12262         GET_SHAPE_CONFIG(EDIT::DRAG_AND_DROP_WINDOW_HEIGHT, orientation, dragWindowDimension.height);
12263
12264         FloatRectangle bounds(__pressedAbsolutePoint.x-dragWindowDimension.width/2.0f, __pressedAbsolutePoint.y-dragWindowDimension.height/2.0f, dragWindowDimension.width, dragWindowDimension.height);
12265
12266         _EditDragAndDropWindow* pDragWindow = new (std::nothrow) _EditDragAndDropWindow();
12267         SysTryReturn(NID_UI_CTRL, pDragWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
12268
12269         r = pDragWindow->CreateRootVisualElement(_WINDOW_TYPE_SUB);
12270         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
12271
12272         pDragWindow->SetBackgroundColor(Color(0, 0, 0, 0));
12273         pDragWindow->SetActivationEnabled(false);
12274         pDragWindow->SetBounds(bounds);
12275
12276         pLabel = _Label::CreateLabelN();
12277         SysTryCatch(NID_UI_CTRL, pLabel, , E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(r));
12278
12279         pLabel->SetBackgroundColor(Color(0, 0, 0, 0));
12280         pLabel->SetBounds(FloatRectangle(0, 0, bounds.width, bounds.height));
12281         pLabel->SetText(__dragAndDropString);
12282         pLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
12283
12284         pDragWindow->AttachChild(*pLabel);
12285         pDragWindow->SetLabel(pLabel);
12286
12287         pDragWindow->Open();
12288
12289         __isCursorDisabled = true;
12290
12291         DrawDragAndDropVisualCue();
12292
12293         return pDragWindow;
12294
12295 CATCH:
12296         delete pDragWindow;
12297
12298         return null;
12299 }
12300
12301 void
12302 _EditPresenter::OnDragAndDropDropping(void)
12303 {
12304         SysLog(NID_UI_CTRL, "Drag & Drop Callback is called");
12305
12306         _Window* pDragWindow = __pEdit->GetDragWindow();
12307         if (pDragWindow)
12308         {
12309                 pDragWindow->Close();
12310                 delete pDragWindow;
12311         }
12312         return;
12313 }
12314
12315 void
12316 _EditPresenter::OnDragAndDropEntered(void)
12317 {
12318         SysLog(NID_UI_CTRL, "Drag & Drop Callback is called");
12319
12320         DrawDragAndDropVisualCue();
12321
12322         return;
12323 }
12324
12325 void
12326 _EditPresenter::OnDragAndDropMoved(const Tizen::Graphics::FloatPoint& position)
12327 {
12328         SysLog(NID_UI_CTRL, "Drag & Drop Callback is called");
12329
12330         if (IsViewModeEnabled())
12331         {
12332                 return;
12333         }
12334
12335         FloatRectangle clientBounds = __pEdit->GetBoundsF();
12336         clientBounds.x = 0.0f;
12337         clientBounds.y = 0.0f;
12338         if (clientBounds.Contains(position))
12339         {
12340                 int rowIndex;
12341                 int columnIndex;
12342                 FloatPoint touchPoint = position;
12343
12344                 if(!(__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE))
12345                 {
12346                         float totalHeight = __pTextObject->GetTotalHeightF();
12347                         if (totalHeight < __textObjectBounds.height)
12348                         {
12349                                 if (totalHeight < touchPoint.y)
12350                                 {
12351                                         touchPoint.y = totalHeight;
12352                                 }
12353                         }
12354                 }
12355
12356                 int cursorPos = GetCursorPositionAt(touchPoint, rowIndex,columnIndex);
12357                 if (cursorPos != -1)
12358                 {
12359                         SetCursorPosition(cursorPos, rowIndex, columnIndex);
12360                 }
12361                 else
12362                 {
12363                         if ((__pEdit->GetEditStyle() & EDIT_STYLE_SINGLE_LINE) == false)
12364                         {
12365                                 SetCursorPosition(GetTextLength());
12366                         }
12367                 }
12368                 InitializeCursor();
12369                 DrawDragAndDropVisualCue();
12370         }
12371         return;
12372 }
12373
12374 void
12375 _EditPresenter::OnDragAndDropLeft(void)
12376 {
12377         SysLog(NID_UI_CTRL, "Drag & Drop Callback is called");
12378
12379         __pDragAndDropCueVisualElement->SetShowState(false);
12380
12381         return;
12382 }
12383
12384 void
12385 _EditPresenter::OnDragAndDropDropped(const _DragAndDropItem& dragAndDropItem)
12386 {
12387         SysLog(NID_UI_CTRL, "Drag & Drop Callback is called");
12388
12389         __pDragAndDropCueVisualElement->SetShowState(false);
12390
12391         if (IsViewModeEnabled())
12392         {
12393                 return;
12394         }
12395
12396         if (IsUnsupportedChracterExist(GetKeypadStyle(), dragAndDropItem.GetData()))
12397         {
12398                 return;
12399         }
12400
12401         if (!IsCurrentFocused())
12402         {
12403                 _Window* pWindow = null;
12404                 _ControlManager* pControlManager = _ControlManager::GetInstance();
12405                 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
12406
12407                 pWindow = pControlManager->GetCurrentFrame();
12408                 if (pWindow)
12409                 {
12410                         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
12411                         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
12412
12413                         bool visible = pEcoreEvas->IsWindowVisible(*pWindow);
12414                         bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*pWindow);
12415
12416                         if ((visible == true) && (activationEnabled == true))
12417                         {
12418                                 pEcoreEvas->ActivateWindow(*pWindow);
12419                         }
12420                 }
12421                 __pEdit->SetFocused();
12422         }
12423
12424         InsertTextAt(__cursorPos, dragAndDropItem.GetData());
12425         DrawText();
12426         return;
12427 }
12428
12429 void
12430 _EditPresenter::DrawDragAndDropVisualCue(void)
12431 {
12432         if (IsViewModeEnabled())
12433         {
12434                 return;
12435         }
12436
12437         FloatRectangle cursorBounds;
12438         if (CalculateCursorBounds(__textObjectBounds, cursorBounds) != E_SUCCESS)
12439         {
12440                 return;
12441         }
12442         __pDragAndDropCueVisualElement->SetShowState(true);
12443         __pDragAndDropCueVisualElement->SetBounds(cursorBounds);
12444
12445         Canvas* pCanvas = __pDragAndDropCueVisualElement->GetCanvasN();
12446         if (pCanvas == null)
12447         {
12448                 return;
12449         }
12450         pCanvas->SetBackgroundColor(Color(0));
12451         pCanvas->Clear();
12452
12453 //      Color cursorColor;
12454 //      GET_COLOR_CONFIG(EDIT::CURSOR_NORMAL, cursorColor);
12455
12456         cursorBounds.SetPosition(0.0f, 0.0f);
12457         pCanvas->FillRectangle(Color::GetColor(COLOR_ID_RED), cursorBounds);
12458
12459         delete pCanvas;
12460
12461         return;
12462 }
12463
12464 void
12465 _EditPresenter::ResetDragAndDrop(void)
12466 {
12467         __dragAndDropStarted = false;
12468         __pEdit->DragAndDropDrop();
12469         if (!IsViewModeEnabled())
12470         {
12471                 __isCursorDisabled = false;
12472                 InitializeCursor();
12473         }
12474         __pDragAndDropCueVisualElement->SetShowState(false);
12475 }
12476
12477 bool
12478 _EditPresenter::IsDragAndDropStarted(void) const
12479 {
12480         return __dragAndDropStarted;
12481 }
12482
12483 }}} // Tizen::Ui::Controls