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