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