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