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