modify Klockwork bug
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_Keypad.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file                 FUiCtrl_Keypad.cpp
20 * @brief                This file contains implementation of _Keypad class
21 *
22 * This file contains implementation of _Keypad class.
23 */
24
25 #include <FBaseSysLog.h>
26 #include <FSysSystemInfo.h>
27 #include <FGrp_BitmapImpl.h>
28 #include <FSys_SettingInfoImpl.h>
29 #include "FUi_AccessibilityContainer.h"
30 #include "FUi_AccessibilityElement.h"
31 #include "FUi_EcoreEvas.h"
32 #include "FUi_EcoreEvasMgr.h"
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUi_SystemUtilImpl.h"
35 #include "FUiAnim_ControlVisualElement.h"
36 #include "FUiAnim_VisualElement.h"
37 #include "FUiAnim_VisualElementImpl.h"
38 #include "FUiCtrlForm.h"
39 #include "FUiCtrl_Indicator.h"
40 #include "FUiCtrl_Edit.h"
41 #include "FUiCtrl_Frame.h"
42 #include "FUiCtrl_Form.h"
43 #include "FUiCtrl_Keypad.h"
44 #include "FUiCtrl_Toolbar.h"
45
46 using namespace Tizen::Graphics;
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Runtime;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Ui::Animations;
51 using namespace Tizen::Ui::Controls;
52 using namespace Tizen::System;
53
54 namespace Tizen { namespace Ui { namespace Controls
55 {
56 const int COMMAND_DONE_BUTTON_ID = 100;
57 const int COMMAND_CANCEL_BUTTON_ID = 101;
58 const int FOOTER_BACK_BUTTON_ID = 102;
59
60 IMPLEMENT_PROPERTY(_Keypad);
61
62 _Keypad::_Keypad(void)
63         : __isFirstCall(true)
64         , __isInitialized(false)
65         , __isSingleLineEnabled(false)
66         , __pIndicator(null)
67         , __pCallerEdit(null)
68         , __pChildEdit(null)
69         , __pFooter(null)
70         , __text()
71         , __pTextEvent(null)
72         , __isCommandButtonPressed(false)
73         , __isPredictionWindowOpendInUSBMode(false)
74 {
75         _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
76         if(pAccessibilityContainer)
77         {
78                 pAccessibilityContainer->Activate(true);
79         }
80
81         _ControlManager::GetInstance()->SetClipboardOwner(this);
82 }
83
84 _Keypad::~_Keypad(void)
85 {
86         _ControlManager::GetInstance()->SetClipboardOwner(null);
87
88         Dispose();
89 }
90
91 _Keypad*
92 _Keypad::CreateKeypadN(void)
93 {
94         ClearLastResult();
95
96         FloatDimension screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
97
98         FloatRectangle portBounds(0.0f, 0.0f, screenSize.width, screenSize.height);
99         FloatRectangle landBounds(0.0f, 0.0f, screenSize.width, screenSize.height);
100         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
101
102         _Keypad* pKeypad = new (std::nothrow) _Keypad;
103         result r = GetLastResult();
104         SysTryCatch(NID_UI_CTRL, pKeypad, , r, "[%s] Propagating.", GetErrorMessage(r));
105         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
106
107         r = pKeypad->CreateRootVisualElement(_WINDOW_TYPE_SUB);
108
109         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
110
111         // For DragAndDrop
112         pEcoreEvas->SetDragAndDropEnabled(*pKeypad);
113
114         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 0, portBounds);
115         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 180, portBounds);
116         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 90, landBounds);
117         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 270, landBounds);
118
119         pKeypad->AcquireHandle();
120
121         return pKeypad;
122
123 CATCH:
124         delete pKeypad;
125
126         return null;
127 }
128
129 result
130 _Keypad::Initialize(int editStyle, _KeypadStyleInfo keypadStyleInfo, int limitLength, _Edit* pCallerEdit)
131 {
132         result r = E_SUCCESS;
133         bool UsbKeyboardConnected = false;
134
135         _ControlManager* pControlManager = _ControlManager::GetInstance();
136         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
137
138         if (GetOwner() == null)
139         {
140                 _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
141                 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM,
142                                         E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
143
144                 _Form* pForm = pFrame->GetCurrentForm();
145
146                 if (pForm)
147                 {
148                         SetOwner(pForm);
149                 }
150                 else
151                 {
152                         SetOwner(pFrame);
153                 }
154         }
155
156         __pFooter = CreateFooter();
157
158         if (!__pFooter)
159         {
160                 SysTryReturnResult(NID_UI_CTRL, __pFooter, GetLastResult(), "Unable to create Footer");
161         }
162
163         if (pCallerEdit)
164         {
165                 __pCallerEdit = pCallerEdit;
166         }
167         else
168         {
169                 __pCallerEdit = null;
170         }
171
172         if (__pChildEdit == null)
173         {
174                 __pChildEdit = _Edit::CreateEditN();
175                 SysTryCatch(NID_UI_CTRL, __pChildEdit, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
176
177                 String doneText;
178                 String cancelText;
179                 _AccessibilityContainer* pAccessibilityContainer = null;
180                 Variant variantKeypadStyle = (int)keypadStyleInfo.keypadStyle;
181
182                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_DONE, doneText);
183                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_CANCEL_ABB, cancelText);
184
185                 __pChildEdit->SetFullScreenKeypadEdit(true);
186
187                 r = __pChildEdit->Initialize(editStyle, INPUT_STYLE_OVERLAY, limitLength);
188                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
189
190                 __pChildEdit->SetTextPredictionEnabled(keypadStyleInfo.textPredictionEnabled);
191                 __pChildEdit->SetKeypadNormalNumberStyle(keypadStyleInfo.isNormalNumberStyle);
192                 __pChildEdit->SetPropertyKeypadStyle(variantKeypadStyle);
193
194                 if (!keypadStyleInfo.enterActionEnabled)//EditField Style
195                 {
196                         __pChildEdit->SetKeypadActionEnabled(false);
197                 }
198
199                 __pChildEdit->SetLowerCaseModeEnabled(keypadStyleInfo.isLowerCaseModeEnabled);
200
201                 r = __pChildEdit->SetKeypadCommandButtonVisible(false);
202                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
203
204                 __pChildEdit->AddKeypadEventListener(*this);
205
206                 r = AttachChild(*__pChildEdit);
207                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
208
209                 pAccessibilityContainer = GetAccessibilityContainer();
210                 if (pAccessibilityContainer)
211                 {
212                         _AccessibilityContainer* pAccessibilityEdit = __pChildEdit->GetAccessibilityContainer();
213                         if (pAccessibilityEdit)
214                         {
215                                 pAccessibilityContainer->AddChildContainer(*pAccessibilityEdit);
216                         }
217                 }
218
219                 if (__pCallerEdit)
220                 {
221                         if (editStyle & EDIT_STYLE_PASSWORD)
222                         {
223                                 __pChildEdit->SetPasswordVisible(__pCallerEdit->IsPasswordVisible());
224                         }
225                 }
226         }
227
228         SetClipChildrenEnabled(false);
229
230         if (!__pIndicator)
231         {
232                 __pIndicator = _Indicator::CreateIndicator();
233                 SysTryCatch(NID_UI_CTRL, __pIndicator, , GetLastResult(), "Unable to create Indicator");
234
235                 _VisualElement* pKeypadVisualElement = GetVisualElement();
236                 pKeypadVisualElement->AttachChild(*__pIndicator);
237
238                 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*__pIndicator);
239                 r = pImpl->SetZOrderGroup(_ControlVisualElement::Z_ORDER_GROUP_CONTROL + 4);
240
241                 float indicatorwidth = 0.0f;
242                 float indicatorheight = 0.0f;
243
244                 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
245                 {
246                         indicatorwidth = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF().width;
247                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
248                 }
249                 else
250                 {
251                         indicatorwidth = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF().height;
252                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
253                 }
254
255                 __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, indicatorwidth, indicatorheight));
256                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
257         }
258
259         UsbKeyboardConnected = __pChildEdit->IsUsbKeyboardConnected();
260
261         r = ChangeLayoutInternal(LAYOUT_CHANGE_NONE);
262         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
263
264         __pChildEdit->SetVisibleState(true);
265
266         __isInitialized = true;
267
268         r = _SettingInfoImpl::AddSettingEventListenerForInternal(*this);
269         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
270
271         return r;
272
273 CATCH:
274         Dispose();
275         return r;
276 }
277
278 result
279 _Keypad::Dispose(void)
280 {
281         result r = E_SUCCESS;
282         if (__pFooter)
283         {
284                 DetachChild(*__pFooter);
285                 delete __pFooter;
286                 __pFooter = null;
287         }
288         if (__pChildEdit)
289         {
290                 DetachChild(*__pChildEdit);
291                 delete __pChildEdit;
292                 __pChildEdit = null;
293         }
294         __pCallerEdit = null;
295
296         if (__pTextEvent)
297         {
298                 delete __pTextEvent;
299                 __pTextEvent = null;
300         }
301
302         if (__pIndicator)
303         {
304                 _VisualElement* pKeypadVisualElement = GetVisualElement();
305                 pKeypadVisualElement->DetachChild(*__pIndicator);
306                 delete __pIndicator;
307                 __pIndicator = null;
308         }
309
310         _SettingInfoImpl::RemoveSettingEventListenerForInternal(*this);
311
312         return r;
313 }
314
315 _Toolbar*
316 _Keypad::CreateFooter(void)
317 {
318         result r = E_SUCCESS;
319
320         _Toolbar* pFooter = null;
321
322         if (!__pFooter)
323         {
324                 _ControlManager* pControlManager = _ControlManager::GetInstance();
325                 SysTryReturn(NID_UI_CTRL, pControlManager, null, E_SYSTEM, "Fail to get ControlManager instance");
326
327                 _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
328                 SysTryReturn(NID_UI_CTRL, pFrame, null, E_SYSTEM, "This instance is not constructed.");
329
330                 String doneText;
331
332                 FloatRectangle bounds(0.0f,0.0f,0.0f,0.0f);
333
334                 FloatDimension screenSize = pControlManager->GetScreenSizeF();
335
336                 pFooter = _Toolbar::CreateToolbarN(false);
337                 SysTryReturn(NID_UI_CTRL, pFooter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
338
339                 r = pFooter->Construct();
340                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
341
342                 r = pFooter->SetStyle(TOOLBAR_TEXT);
343                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
344
345                 pFooter->SetResizable(true);
346                 pFooter->SetMovable(true);
347
348                 _ControlOrientation orientation = GetOrientation();
349
350                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
351                 {
352                         bounds.width = screenSize.width;
353                 }
354                 else
355                 {
356                         bounds.width = screenSize.height;
357                 }
358
359                 float height = 0.0f;
360                 GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, height);
361                 bounds.height = height;
362
363                 r = pFooter->SetBounds(bounds);
364                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
365
366                 pFooter->SetResizable(false);
367                 pFooter->SetMovable(false);
368
369                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_DONE, doneText);
370
371                 r = pFooter->AddItem(CreateButtonItemN(COMMAND_DONE_BUTTON_ID, doneText));
372                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
373
374                 pFooter->AddActionEventListener(*this);
375
376                 r = AttachChild(*pFooter);
377                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
378
379                 return pFooter;
380
381         }
382         else
383         {
384                 return __pFooter;
385         }
386
387 CATCH:
388         delete pFooter;
389         return null;
390 }
391
392 _Button*
393 _Keypad::CreateButtonItemN(int actionId, const String& text)
394 {
395         result r = E_SUCCESS;
396         _Button* pButton = _Button::CreateButtonN();
397         SysTryReturn(NID_UI_CTRL, pButton, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
398
399         r = pButton->SetActionId(actionId);
400         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
401
402         r = pButton->SetText(text);
403         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
404
405         return pButton;
406 CATCH:
407         delete pButton;
408
409         return null;
410 }
411
412 result
413 _Keypad::ChangeLayoutInternal(LayoutChangeState layoutChangeState)
414 {
415         result r = E_SUCCESS;
416         _ControlManager* pControlManager = _ControlManager::GetInstance();
417         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
418         FloatDimension screenSize = pControlManager->GetScreenSizeF();
419         _ControlOrientation orientation = GetOrientation();
420
421         _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
422         SysTryReturn(NID_UI_CTRL, pFrame, null, E_SYSTEM, "This instance is not constructed.");
423
424         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
425         FloatRectangle keypadRect(0.0f, 0.0f, 0.0f, 0.0f);
426         float indicatorHeight = 0.0f;
427         float clipboardHeight = 0.0f;
428         bool isKeypadExist = false;
429         bool isClipboardExist = false;
430
431         FloatDimension indicatorDimension(0.0f, 0.0f);
432         FloatDimension keypadDimsnsion(0.0f, 0.0f);
433
434         if (__isInitialized || __pChildEdit->IsUsbKeyboardConnected())
435         {
436                 isKeypadExist = __pChildEdit->CheckKeypadExist(orientation);
437                 isClipboardExist = __pChildEdit->IsClipboardExist();
438         }
439
440         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
441         {
442                 bounds.width = screenSize.width;
443                 bounds.height = screenSize.height;
444         }
445         else
446         {
447                 bounds.width = screenSize.height;
448                 bounds.height = screenSize.width;
449         }
450
451         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
452         {
453                 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorHeight);
454         }
455
456         indicatorDimension.height = indicatorHeight;
457
458         SetResizable(true);
459         SetMovable(true);
460         r = SetBounds(CoordinateSystem::AlignToDevice(bounds));
461         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
462         SetResizable(false);
463         SetMovable(false);
464
465         FloatRectangle editRect = CoordinateSystem::AlignToDevice(bounds);
466
467         editRect.y = CoordinateSystem::AlignToDevice(indicatorDimension).height;
468
469         float footerHeight = 0.0f;
470         FloatDimension footerDimension(0.0f, 0.0f);
471
472         GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, footerHeight);
473         footerDimension.height = footerHeight;
474
475         editRect.height -= CoordinateSystem::AlignToDevice(indicatorDimension).height;
476         editRect.height -= CoordinateSystem::AlignToDevice(footerDimension).height;
477
478         if ((isClipboardExist && layoutChangeState == LAYOUT_CHANGE_ROTATE))
479         {
480                 ;
481         }
482         else
483         {
484                 if (isKeypadExist || isClipboardExist)
485                 {
486                         if (isKeypadExist)
487                         {
488                                 r = __pChildEdit->GetKeypadBounds(keypadRect);
489                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
490                         }
491
492                         if (isClipboardExist)
493                         {
494                                 clipboardHeight = __pChildEdit->GetClipboardHeight();
495                         }
496
497                         if (clipboardHeight > keypadRect.height)
498                         {
499                                 keypadDimsnsion.height = clipboardHeight;
500                         }
501                         else
502                         {
503                                 keypadDimsnsion.height = keypadRect.height;
504                         }
505
506                         editRect.height -= CoordinateSystem::AlignToDevice(keypadDimsnsion).height;
507                 }
508         }
509
510         r = __pChildEdit->SetBounds(editRect);
511         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS,  r, r, "[%s] Propagating.", GetErrorMessage(r));
512
513         FloatRectangle footerBounds(0.0f, 0.0f, 0.0f, 0.0f);
514
515         footerBounds.y = editRect.height + CoordinateSystem::AlignToDevice(indicatorDimension).height;
516         footerBounds.width = editRect.width;
517         footerBounds.height = CoordinateSystem::AlignToDevice(footerDimension).height;
518
519         __pFooter->SetResizable(true);
520         __pFooter->SetMovable(true);
521
522         __pFooter->SetBounds(footerBounds);
523
524         __pFooter->SetResizable(false);
525         __pFooter->SetMovable(false);
526
527         SysLog(NID_UI_CTRL, "[FULLEDIT] ChangeLayoutInternal Draw FullScreen window- Footer position(%f, %f, %f, %f)", footerBounds.x, footerBounds.y, footerBounds.width, footerBounds.height);
528         Invalidate(true);
529
530         return r;
531 }
532
533 result
534 _Keypad::OnAttachedToMainTree(void)
535 {
536         result r = E_SUCCESS;
537
538         GetEcoreEvasMgr()->GetEcoreEvas()->SetOwner(*this, *GetOwner());//set owner to EcoreEvas for orientation set.
539
540         r = __pChildEdit->SetText(__text);
541         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
542
543         if (__pIndicator)
544         {
545                 __pIndicator->OnAttachedToMainTree();
546                 __pIndicator->AddIndicatorObject(this, GetRootWindow());
547                 __pIndicator->SetIndicatorShowState(true);
548                 __pIndicator->SetIndicatorAutoHide(false, true);
549         }
550
551         Invalidate(true);
552
553         return r;
554 }
555
556 result
557 _Keypad::OnDetachingFromMainTree(void)
558 {
559         if (__pIndicator)
560         {
561                 __pIndicator->DeleteIndicatorObject();
562         }
563
564         if (__pCallerEdit && !__pCallerEdit->IsInputEventEnabled())
565         {
566                 __pCallerEdit->UnlockInputEvent();
567         }
568
569         return _Window::OnDetachingFromMainTree();
570 }
571
572 void
573 _Keypad::OnNativeWindowActivated(void)
574 {
575         if (__isFirstCall && __pChildEdit)
576         {
577                 __pChildEdit->SetFocused();
578                 __isFirstCall = false;
579                 ChangeLayoutInternal(LAYOUT_CHANGE_NONE);
580         }
581
582         return;
583 }
584
585 bool
586 _Keypad::IsRotationSynchronized(void) const
587 {
588         return true;
589 }
590
591 void
592 _Keypad::OnDraw(void)
593 {
594         Color backgroundColor;
595         GET_COLOR_CONFIG(EDIT::BG_NORMAL, backgroundColor);
596         SetBackgroundColor(backgroundColor);
597
598         return;
599 }
600
601 result
602 _Keypad::SetSingleLineEnabled(bool enabled)
603 {
604         SetProperty("singleLineEnabled", Variant(enabled));
605
606         return E_SUCCESS;
607 }
608
609 bool
610 _Keypad::IsSingleLineEnabled(void) const
611 {
612         Variant enabled = GetProperty("singleLineEnabled");
613
614         return enabled.ToBool();
615 }
616
617 result
618 _Keypad::SetPropertySingleLineEnabled(const Variant& enabled)
619 {
620         __isSingleLineEnabled = enabled.ToBool();
621
622         return E_SUCCESS;
623 }
624
625 Variant
626 _Keypad::GetPropertySingleLineEnabled(void) const
627 {
628         return Variant(__isSingleLineEnabled);
629 }
630
631 String
632 _Keypad::GetText(void) const
633 {
634         Variant text = GetProperty("text");
635
636         return text.ToString();
637 }
638
639 void
640 _Keypad::SetText(const String& text)
641 {
642         SetProperty("text", Variant(text));
643
644         return;
645 }
646
647 result
648 _Keypad::SetPropertyText(const Variant& text)
649 {
650         __text = text.ToString();
651
652         return E_SUCCESS;
653 }
654
655 Variant
656 _Keypad::GetPropertyText(void) const
657 {
658         return Variant(__text);
659 }
660
661 result
662 _Keypad::AddTextEventListener(const _ITextEventListener& listener)
663 {
664         if (__pTextEvent == null)
665         {
666                 __pTextEvent = _TextEvent::CreateInstanceN(*this);
667                 SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.\n");
668         }
669
670         return __pTextEvent->AddListener(listener);
671 }
672
673 result
674 _Keypad::RemoveTextEventListener(const _ITextEventListener& listener)
675 {
676         SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance isn't constructed.");
677         __pTextEvent->RemoveListener(listener);
678
679         return E_SUCCESS;
680 }
681
682 void
683 _Keypad::SetEditTextFilter(IEditTextFilter* pFilter)
684 {
685         if (__pChildEdit)
686         {
687                 __pChildEdit->SetEditTextFilter(pFilter);
688         }
689
690         return;
691 }
692
693 void
694 _Keypad::SendOpaqueCommand (const Tizen::Base::String& command)
695 {
696         if (__pChildEdit)
697         {
698                 __pChildEdit->SendOpaqueCommand(command);
699         }
700
701         return;
702 }
703
704 bool
705 _Keypad::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
706 {
707         if (keyInfo.GetKeyCode() == _KEY_ESC || keyInfo.GetKeyCode() == _KEY_BACK)
708         {
709                 OnActionPerformed(source, FOOTER_BACK_BUTTON_ID);
710         }
711
712         return true;
713 }
714
715 void
716 _Keypad::OnActionPerformed(const _Control& source, int actionId)
717 {
718         bool isReCreationLock = false;
719         if ((actionId != COMMAND_DONE_BUTTON_ID) && (actionId != FOOTER_BACK_BUTTON_ID))
720         {
721                 return;
722         }
723
724         __pChildEdit->HideKeypad();
725
726         if (__pCallerEdit)
727         {
728                 __pCallerEdit->SetKeypadEnabled(false);
729                 isReCreationLock = true;
730         }
731         Close();
732         if (isReCreationLock)
733         {
734                 __pCallerEdit->SetKeypadEnabled(true);
735         }
736
737         CoreTextEventStatus textEventStatus = CORE_TEXT_EVENT_CHANGED;
738         if (actionId == COMMAND_DONE_BUTTON_ID)
739         {
740                 __text = __pChildEdit->GetText();
741                 textEventStatus = CORE_TEXT_EVENT_CHANGED;
742         }
743         else
744         {
745                 textEventStatus = CORE_TEXT_EVENT_CANCELED;
746         }
747
748         __isCommandButtonPressed = true;
749
750         if (__pCallerEdit)
751         {
752                 __pCallerEdit->SetText(__text);
753                 _Control* pParent = __pCallerEdit->GetParent();
754                 if (pParent)
755                 {
756                         pParent->Invalidate(true);
757                 }
758
759                 __pCallerEdit->SendTextEvent(textEventStatus);
760         }
761         else
762         {
763                 GetOwner()->Invalidate(true);
764                 if (__pTextEvent)
765                 {
766                         IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(textEventStatus);
767                         if (pEventArg)
768                         {
769                                 __pTextEvent->Fire(*pEventArg);
770                         }
771                 }
772         }
773
774         return;
775 }
776
777 void
778 _Keypad::OnKeypadWillOpen(void)
779 {
780         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadWillOpen");
781         return;
782 }
783
784 void
785 _Keypad::OnKeypadOpened(void)
786 {
787         if (__pChildEdit->IsUsbKeyboardConnected())
788         {
789                 __isPredictionWindowOpendInUSBMode = true;
790         }
791
792         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadOpened");
793
794         ChangeLayoutInternal(LAYOUT_CHANGE_KEYPAD_SHOW);//usb off & bounded or usb on & prediction
795
796         return;
797 }
798
799 void
800 _Keypad::OnKeypadClosed(void)
801 {
802         __isPredictionWindowOpendInUSBMode = false;
803
804         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadClosed");
805
806         ChangeLayoutInternal(LAYOUT_CHANGE_KEYPAD_HIDE);
807
808         return;
809 }
810
811 void
812 _Keypad::OnKeypadBoundsChanged(void)
813 {
814         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadBoundsChanged");
815
816         ChangeLayoutInternal(LAYOUT_CHANGE_KEYPAD_BOUNDS_CHANGED);// predictive window show/hide
817
818         return;
819 }
820
821 void
822 _Keypad::OnKeypadActionPerformed(CoreKeypadAction keypadAction)
823 {
824         return;
825 }
826
827 void
828 _Keypad::OnChangeLayout(_ControlOrientation orientation)
829 {
830         float indicatorheight = 0.0f;
831
832         const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
833         const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
834
835         if (__pIndicator)
836         {
837                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
838                 {
839                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
840                         __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, portraitSize.width, indicatorheight));
841                 }
842                 else
843                 {
844                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
845                         __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, landscapeSize.width, indicatorheight));
846                 }
847
848                 __pIndicator->OnChangeLayout(orientation);
849         }
850
851         if (__isInitialized)
852         {
853                 ChangeLayoutInternal(LAYOUT_CHANGE_ROTATE);
854         }
855
856         return;
857 }
858
859 void
860 _Keypad::OnSettingChanged(String& key)
861 {
862         const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
863         if (key == LOCALE_LANGUAGE)
864         {
865                 if (__pFooter)
866                 {
867                         _Button* pButton = __pFooter->GetItem(0);
868                         if (pButton)
869                         {
870                                 String doneText;
871                                 GET_STRING_CONFIG(IDS_TPLATFORM_BUTTON_DONE, doneText);
872                                 pButton->SetText(doneText);
873                         }
874                 }
875         }
876 }
877
878 bool
879 _Keypad::IsLayoutChangable(void) const
880 {
881         return true;
882 }
883
884 void
885 _Keypad::OnActivated(void)
886 {
887         _Window::OnActivated();
888
889         if (__pIndicator)
890         {
891                 __pIndicator->Activate();
892         }
893 }
894
895 void
896 _Keypad::OnDeactivated(void)
897 {
898         _Window::OnDeactivated();
899
900         if (__pIndicator)
901         {
902                 __pIndicator->Deactivate();
903         }
904 }
905
906 } } } // Tizen::Ui::Controls