Change keypad UI logic for Tizen2.1 concept
[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 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_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 <FGrp_BitmapImpl.h>
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29 #include "FUi_EcoreEvas.h"
30 #include "FUi_EcoreEvasMgr.h"
31 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_SystemUtilImpl.h"
33 #include "FUiCtrlForm.h"
34 #include "FUiCtrl_Edit.h"
35 #include "FUiCtrl_Frame.h"
36 #include "FUiCtrl_Form.h"
37 #include "FUiCtrl_Keypad.h"
38 #include "FUiCtrl_Toolbar.h"
39
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Runtime;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Ui::Controls;
45
46 namespace Tizen { namespace Ui { namespace Controls
47 {
48 const int COMMAND_DONE_BUTTON_ID = 100;
49 const int COMMAND_CANCEL_BUTTON_ID = 101;
50 const int FOOTER_BACK_BUTTON_ID = 102;
51
52 IMPLEMENT_PROPERTY(_Keypad);
53
54 _Keypad::_Keypad(void)
55         : __isInitialized(false)
56         , __isSingleLineEnabled(false)
57         , __pOwner(null)
58         , __pCallerEdit(null)
59         , __pChildEdit(null)
60         , __pFooter(null)
61         , __text()
62         , __pTextEvent(null)
63         , __isCommandButtonPressed(false)
64         , __isPredictionWindowOpendInUSBMode(false)
65 {
66         _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
67         if(pAccessibilityContainer)
68         {
69                 pAccessibilityContainer->Activate(true);
70         }
71 }
72
73 _Keypad::~_Keypad(void)
74 {
75         Dispose();
76 }
77
78 _Keypad*
79 _Keypad::CreateKeypadN(void)
80 {
81         ClearLastResult();
82
83         _Keypad* pKeypad = new (std::nothrow) _Keypad;
84         result r = GetLastResult();
85         SysTryCatch(NID_UI_CTRL, pKeypad, , r, "[%s] Propagating.", GetErrorMessage(r));
86         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
87
88         r = pKeypad->CreateRootVisualElement();
89         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
90
91         pKeypad->AcquireHandle();
92
93         return pKeypad;
94
95 CATCH:
96         delete pKeypad;
97
98         return null;
99 }
100
101 result
102 _Keypad::Initialize(int editStyle, _KeypadStyleInfo keypadStyleInfo, int limitLength, _Edit* pCallerEdit)
103 {
104         result r = E_SUCCESS;
105         bool UsbKeyboardConnected = false;
106
107         _ControlManager* pControlManager = _ControlManager::GetInstance();
108         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
109
110         if (GetOwner() == null)
111         {
112                 _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
113                 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM,
114                                         E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
115
116                 _Form* pForm = pFrame->GetCurrentForm();
117
118                 if (pForm)
119                 {
120                         SetOwner(pForm);
121                         __pOwner = pForm;
122                 }
123                 else
124                 {
125                         SetOwner(pFrame);
126                         __pOwner = pFrame;
127                 }
128         }
129         else
130         {
131                 __pOwner = GetOwner();
132         }
133
134         __pFooter = CreateFooter();
135
136         if (!__pFooter)
137         {
138                 SysTryReturnResult(NID_UI_CTRL, __pFooter, GetLastResult(), "Unable to create Edit");
139         }
140
141         if (pCallerEdit)
142         {
143                 __pCallerEdit = pCallerEdit;
144         }
145         else
146         {
147                 __pCallerEdit = null;
148         }
149
150         if ( __pChildEdit == null)
151         {
152                 __pChildEdit = _Edit::CreateEditN();
153                 SysTryReturnResult(NID_UI_CTRL, __pChildEdit, E_OUT_OF_MEMORY, "Unable to create Edit");
154
155                 String doneText;
156                 String cancelText;
157                 _AccessibilityContainer* pAccessibilityContainer = null;
158
159                 GET_STRING_CONFIG(IDS_COM_SK_DONE, doneText);
160                 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
161
162                 __pChildEdit->SetFullScreenKeypadEdit(true);
163
164                 r = __pChildEdit->Initialize(editStyle, INPUT_STYLE_OVERLAY, limitLength);
165                 SysTryCatch(NID_UI_CTRL, __pChildEdit, , r, "[%s] Propagating.", GetErrorMessage(r));
166
167                 __pChildEdit->SetTextPredictionEnabled(keypadStyleInfo.textPredictionEnabled);
168                 __pChildEdit->SetKeypadNormalNumberStyle(keypadStyleInfo.isNormalNumberStyle);
169                 __pChildEdit->SetKeypadStyle(keypadStyleInfo.keypadStyle);
170                 if (!keypadStyleInfo.enterActionEnabled)//EditField Style
171                 {
172                         __pChildEdit->SetKeypadActionEnabled(false);
173                 }
174
175                 __pChildEdit->SetLowerCaseModeEnabled(keypadStyleInfo.isLowerCaseModeEnabled);
176
177                 r = __pChildEdit->SetKeypadCommandButtonVisible(false);
178                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
179
180                 __pChildEdit->AddKeypadEventListener(*this);
181
182                 r = AttachChild(*__pChildEdit);
183                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
184
185                 pAccessibilityContainer = GetAccessibilityContainer();
186                 if (pAccessibilityContainer)
187                 {
188                         _AccessibilityContainer* pAccessibilityEdit = __pChildEdit->GetAccessibilityContainer();
189                         if (pAccessibilityEdit)
190                         {
191                                 pAccessibilityContainer->AddChildContainer(*pAccessibilityEdit);
192                         }
193                 }
194         }
195
196         UsbKeyboardConnected = __pChildEdit->IsUsbKeyboardConnected();
197
198         r = ChangeLayoutInternal();
199
200         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
201
202         __pChildEdit->SetVisibleState(true);
203
204         __isInitialized = true;
205
206         return r;
207
208 CATCH:
209         Dispose();
210         return r;
211 }
212
213 _Toolbar*
214 _Keypad::CreateFooter(void)
215 {
216         result r = E_SUCCESS;
217
218         _Toolbar* pFooter = null;
219
220         if (!__pFooter)
221         {
222                 _ControlManager* pControlManager = _ControlManager::GetInstance();
223                 SysTryReturn(NID_UI_CTRL, pControlManager, null, E_SYSTEM, "Fail to get ControlManager instance");
224
225                 _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
226                 SysTryReturn(NID_UI_CTRL, pFrame, null, E_SYSTEM, "This instance is not constructed.");
227
228                 String doneText;
229
230                 FloatRectangle bounds(0.0f,0.0f,0.0f,0.0f);
231
232                 FloatDimension screenSize = pControlManager->GetScreenSizeF();
233
234                 pFooter = _Toolbar::CreateToolbarN(false);
235                 SysTryReturn(NID_UI_CTRL, pFooter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create instance.");
236
237                 r = pFooter->Construct();
238                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
239
240                 r = pFooter->SetStyle(TOOLBAR_TEXT);
241                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
242
243                 pFooter->SetResizable(true);//[twt] is it necessary???????
244                 pFooter->SetMovable(true);
245
246                 _ControlOrientation orientation = GetOrientation();
247
248                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
249                 {
250                         bounds.width = screenSize.width;
251                 }
252                 else
253                 {
254                         bounds.width = screenSize.height;
255                 }
256
257                 float height = 0.0f;
258                 GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, height);
259                 bounds.height = height;
260
261                 r = pFooter->SetBounds(bounds);
262                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
263
264                 pFooter->SetResizable(false);
265                 pFooter->SetMovable(false);
266
267                 GET_STRING_CONFIG(IDS_COM_SK_DONE, doneText);
268                 //GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
269
270                 r = pFooter->AddItem(CreateButtonItemN(COMMAND_DONE_BUTTON_ID, doneText));
271                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
272
273                 pFooter->SetBackEventListener(*this, FOOTER_BACK_BUTTON_ID);
274                 pFooter->AddActionEventListener(*this);
275
276                 pFooter->SetButton(BACK_BUTTON, CreateFooterBackButton(pFooter));
277
278                 r = AttachChild(*pFooter);
279                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
280
281                 return pFooter;
282
283         }
284         else
285         {
286                 return __pFooter;
287         }
288
289 CATCH:
290         delete pFooter;
291         return null;
292 }
293
294 _Button*
295 _Keypad::CreateFooterBackButton(_Toolbar* pFooter)
296 {
297         _Button* pButton = _Button::CreateButtonN();
298
299         float buttonHeight = 0.0f;
300         float buttonWidth = 0.0f;
301         float iconSize = 0.0f;
302
303         GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_HEIGHT, pFooter->GetOrientation(), buttonHeight);
304         GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_WIDTH, pFooter->GetOrientation(), buttonWidth);
305         GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_ICON_SIZE, pFooter->GetOrientation(), iconSize);
306
307         pButton->SetSize(FloatDimension(buttonWidth, buttonHeight));
308
309         Bitmap* pBackgroundNormalBitmap = null;
310         Bitmap* pBackgroundPressedBitmap = null;
311         Bitmap* pColorReplacedBitmap = null;
312         Bitmap* pBackIconNormalBitmap = null;
313         Bitmap* pBackIconNormalEffectBitmap = null;
314
315         GET_BITMAP_CONFIG_N(FOOTER::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundNormalBitmap);
316         GET_BITMAP_CONFIG_N(FOOTER::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundPressedBitmap);
317         GET_BITMAP_CONFIG_N(FOOTER::BACK_ICON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackIconNormalBitmap);
318         GET_BITMAP_CONFIG_N(FOOTER::BACK_ICON_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackIconNormalEffectBitmap);
319
320         bool themeBackNormalBitmap = IS_CUSTOM_BITMAP(FOOTER::BACK_ICON_NORMAL);
321         if (!themeBackNormalBitmap)
322         {
323                 GET_BITMAP_CONFIG_N(FOOTER::BACK_ICON_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackIconNormalEffectBitmap);
324         }
325
326         if (pBackgroundNormalBitmap)
327         {
328                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA),
329                                 pFooter->GetButtonColor(_BUTTON_STATUS_NORMAL));
330                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_NORMAL, *pColorReplacedBitmap);
331                 delete pColorReplacedBitmap;
332
333                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA),
334                                 pFooter->GetButtonColor(_BUTTON_STATUS_HIGHLIGHTED));
335                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_HIGHLIGHTED, *pColorReplacedBitmap);
336                 delete pColorReplacedBitmap;
337
338                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA),
339                                 pFooter->GetButtonColor(_BUTTON_STATUS_DISABLED));
340                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_DISABLED, *pColorReplacedBitmap);
341                 delete pColorReplacedBitmap;
342
343                 delete pBackgroundNormalBitmap;
344         }
345
346         if (pBackgroundPressedBitmap)
347         {
348                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundPressedBitmap, Color::GetColor(COLOR_ID_MAGENTA),
349                                 pFooter->GetButtonColor(_BUTTON_STATUS_PRESSED));
350                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_PRESSED, *pColorReplacedBitmap);
351                 delete pColorReplacedBitmap;
352
353                 delete pBackgroundPressedBitmap;
354         }
355
356         if (pBackIconNormalBitmap)
357         {
358                 Color normalColor;
359                 Color pressedColor;
360                 Color disabledColor;
361
362                 GET_COLOR_CONFIG(FOOTER::BACK_ICON_NORMAL, normalColor);
363                 GET_COLOR_CONFIG(FOOTER::BACK_ICON_PRESSED, pressedColor);
364                 GET_COLOR_CONFIG(FOOTER::BACK_ICON_DISABLED, disabledColor);
365
366                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackIconNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalColor);
367                 if (pColorReplacedBitmap)
368                 {
369                         pColorReplacedBitmap->Scale(FloatDimension(iconSize, iconSize));
370
371                         pButton->SetBitmap(_BUTTON_STATUS_NORMAL, FloatPoint(0.0f, 0.0f), *pColorReplacedBitmap);
372
373                         delete pColorReplacedBitmap;
374                 }
375
376                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackIconNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
377                 if (pColorReplacedBitmap)
378                 {
379                         pColorReplacedBitmap->Scale(FloatDimension(iconSize, iconSize));
380
381                         pButton->SetBitmap(_BUTTON_STATUS_PRESSED, FloatPoint(0.0f, 0.0f), *pColorReplacedBitmap);
382                         delete pColorReplacedBitmap;
383                 }
384
385                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackIconNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), disabledColor);
386                 if (pColorReplacedBitmap)
387                 {
388                         pColorReplacedBitmap->Scale(FloatDimension(iconSize, iconSize));
389
390                         pButton->SetBitmap(_BUTTON_STATUS_DISABLED, FloatPoint(0.0f, 0.0f), *pColorReplacedBitmap);
391                         delete pColorReplacedBitmap;
392                 }
393
394                 delete pBackIconNormalBitmap;
395         }
396
397         if (pBackIconNormalEffectBitmap)
398         {
399                 pButton->SetEffectBitmap(_BUTTON_STATUS_NORMAL, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
400                 pButton->SetEffectBitmap(_BUTTON_STATUS_PRESSED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
401                 pButton->SetEffectBitmap(_BUTTON_STATUS_SELECTED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
402                 pButton->SetEffectBitmap(_BUTTON_STATUS_HIGHLIGHTED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
403                 pButton->SetEffectBitmap(_BUTTON_STATUS_DISABLED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
404
405                 delete pBackIconNormalEffectBitmap;
406         }
407
408         return pButton;
409 }
410
411 _Button*
412 _Keypad::CreateButtonItemN(int actionId, const String& text)
413 {
414         result r = E_SUCCESS;
415         _Button* pButton = _Button::CreateButtonN();
416         SysTryReturn(NID_UI_CTRL, pButton, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create instance.");
417
418         r = pButton->SetActionId(actionId);
419         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
420
421         r = pButton->SetText(text);
422         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
423
424         return pButton;
425 CATCH:
426         delete pButton;
427
428         return null;
429 }
430
431 result
432 _Keypad::ChangeLayoutInternal(void)
433 {
434         result r = E_SUCCESS;
435         _ControlManager* pControlManager = _ControlManager::GetInstance();
436         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
437         FloatDimension screenSize = pControlManager->GetScreenSizeF();
438         _ControlOrientation orientation = GetOrientation();
439
440         _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
441         SysTryReturn(NID_UI_CTRL, pFrame, null, E_SYSTEM, "This instance is not constructed.");
442
443         _Form* pForm = pFrame->GetCurrentForm();
444
445         FloatRectangle bounds;
446         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
447         {
448                 bounds.width = screenSize.width;
449                 bounds.height = screenSize.height;
450         }
451         else
452         {
453                 bounds.width = screenSize.height;
454                 bounds.height = screenSize.width;
455         }
456
457         if (pForm && pForm->IsIndicatorVisible())
458         {
459                 float indicatorHeight = pForm->GetIndicatorBoundsF().height;
460                 bounds.y += indicatorHeight;
461                 bounds.height -= indicatorHeight;
462         }
463
464         SetResizable(true);
465         SetMovable(true);
466         r = SetBounds(bounds);
467         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
468         SetResizable(false);
469         SetMovable(false);
470
471         __pChildEdit->ChangeLayout(orientation);
472
473         FloatRectangle editRect = bounds;
474
475         editRect.y = 0.0f;//_keypad's client doesn't include indicator
476
477         float footerHeight = 0.0f;
478         GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, footerHeight);
479
480         editRect.height -= footerHeight;
481
482         FloatRectangle keypadRect;
483         if (__pChildEdit->IsKeypadExist())
484         {
485                 r = __pChildEdit->GetKeypadBounds(keypadRect);
486                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
487                 editRect.height -= keypadRect.height;
488
489                 if (!__isPredictionWindowOpendInUSBMode)
490                 {
491                         __pFooter->SetHideButton(true);
492                         __pFooter->Invalidate(true);
493                 }
494         }
495         else
496         {
497                 __pFooter->SetHideButton(false);
498                 __pFooter->Invalidate(true);
499         }
500
501         r = __pChildEdit->SetBounds(editRect);
502         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS,  r, r, "[%s] Propagating.", GetErrorMessage(r));
503
504         FloatRectangle footerBounds(0.0f, 0.0f, 0.0f, 0.0f);
505
506         footerBounds.y = editRect.height;
507         footerBounds.width = editRect.width;
508         footerBounds.height = footerHeight;
509
510         __pFooter->SetResizable(true);
511         __pFooter->SetMovable(true);
512
513         __pFooter->SetBounds(footerBounds);
514
515         __pFooter->SetResizable(false);
516         __pFooter->SetMovable(false);
517
518         return r;
519 }
520
521 FloatRectangle
522 _Keypad::GetIndicatorBounds(void) const
523 {
524         float indicatorwidth = 0.0f;
525         float indicatorheight = 0.0f;
526
527         GET_SHAPE_CONFIG(FORM::INDICATOR_WIDTH, GetOrientation(), indicatorwidth);
528         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
529
530         FloatRectangle rect (0.0f, 0.0f, indicatorwidth, indicatorheight);
531
532         return rect;
533 }
534
535 result
536 _Keypad::OnAttachedToMainTree(void)
537 {
538         result r = E_SUCCESS;
539
540         r = __pChildEdit->SetText(__text);
541         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
542
543         Invalidate(true);
544
545         return r;
546 }
547
548 void
549 _Keypad::OnNativeWindowActivated(void)
550 {
551         __pChildEdit->SetFocused();
552
553         return;
554 }
555
556 void
557 _Keypad::OnDraw(void)
558 {
559         Canvas* pCanvas = GetCanvasN();
560         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
561
562         Color backgroundColor;
563         GET_COLOR_CONFIG(EDIT::BG_NORMAL, backgroundColor);
564
565         pCanvas->SetBackgroundColor(backgroundColor);
566         pCanvas->Clear();
567         delete pCanvas;
568
569         return;
570 }
571
572 result
573 _Keypad::SetSingleLineEnabled(bool enabled)
574 {
575         SetProperty("singleLineEnabled", Variant(enabled));
576
577         return E_SUCCESS;
578 }
579
580 bool
581 _Keypad::IsSingleLineEnabled(void) const
582 {
583         Variant enabled = GetProperty("singleLineEnabled");
584
585         return enabled.ToBool();
586 }
587
588 result
589 _Keypad::SetPropertySingleLineEnabled(const Variant& enabled)
590 {
591         __isSingleLineEnabled = enabled.ToBool();
592
593         return E_SUCCESS;
594 }
595
596 Variant
597 _Keypad::GetPropertySingleLineEnabled(void) const
598 {
599         return Variant(__isSingleLineEnabled);
600 }
601
602 String
603 _Keypad::GetText(void) const
604 {
605         Variant text = GetProperty("text");
606
607         return text.ToString();
608 }
609
610 void
611 _Keypad::SetText(const String& text)
612 {
613         SetProperty("text", Variant(text));
614
615         return;
616 }
617
618 result
619 _Keypad::SetPropertyText(const Variant& text)
620 {
621         __text = text.ToString();
622
623         return E_SUCCESS;
624 }
625
626 Variant
627 _Keypad::GetPropertyText(void) const
628 {
629         return Variant(__text);
630 }
631
632 result
633 _Keypad::AddTextEventListener(const _ITextEventListener& listener)
634 {
635         if (__pTextEvent == null)
636         {
637                 __pTextEvent = _TextEvent::CreateInstanceN(*this);
638                 SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.\n");
639         }
640
641         return __pTextEvent->AddListener(listener);
642 }
643
644 result
645 _Keypad::RemoveTextEventListener(const _ITextEventListener& listener)
646 {
647         SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance isn't constructed.");
648         __pTextEvent->RemoveListener(listener);
649
650         return E_SUCCESS;
651 }
652
653 void
654 _Keypad::SetEditTextFilter(IEditTextFilter* pFilter)
655 {
656         if (__pChildEdit)
657         {
658                 __pChildEdit->SetEditTextFilter(pFilter);
659         }
660
661         return;
662 }
663
664 void
665 _Keypad::SendOpaqueCommand (const Tizen::Base::String& command)
666 {
667         if (__pChildEdit)
668         {
669                 __pChildEdit->SendOpaqueCommand(command);
670         }
671
672         return;
673 }
674
675 void
676 _Keypad::OnActionPerformed(const _Control& source, int actionId)
677 {
678         bool isReCreationLock = false;
679         if ((actionId != COMMAND_DONE_BUTTON_ID) && (actionId != FOOTER_BACK_BUTTON_ID))
680         {
681                 return;
682         }
683         if (actionId == FOOTER_BACK_BUTTON_ID)
684         {
685                 if (__pChildEdit->IsKeypadExist())
686                 {
687                         _SystemUtilImpl::GenerateKeyEvent(KEY_EVENT_TYPE_PRESSED, _KEY_STOP);
688                         _SystemUtilImpl::GenerateKeyEvent(KEY_EVENT_TYPE_RELEASED, _KEY_STOP);
689                         return;
690                 }
691         }
692
693         __pChildEdit->HideKeypad();
694
695         if (__pCallerEdit)
696         {
697                 __pCallerEdit->SetKeypadEnabled(false);
698                 isReCreationLock = true;
699         }
700         Close();
701         if (isReCreationLock)
702         {
703                 __pCallerEdit->SetKeypadEnabled(true);
704         }
705
706         CoreTextEventStatus textEventStatus = CORE_TEXT_EVENT_CHANGED;
707         if (actionId == COMMAND_DONE_BUTTON_ID)
708         {
709                 __text = __pChildEdit->GetText();
710                 textEventStatus = CORE_TEXT_EVENT_CHANGED;
711         }
712         else
713         {
714                 textEventStatus = CORE_TEXT_EVENT_CANCELED;
715         }
716
717         __isCommandButtonPressed = true;
718
719         if (__pCallerEdit)
720         {
721                 __pCallerEdit->SetText(__text);
722                 _Control* pParent = __pCallerEdit->GetParent();
723                 if (pParent)
724                 {
725                         pParent->Invalidate(true);
726                 }
727
728                 if (!__pCallerEdit->IsInputEventEnabled())
729                 {
730                         __pCallerEdit->UnlockInputEvent();
731                 }
732                 __pCallerEdit->SendTextEvent(textEventStatus);
733         }
734         else
735         {
736                 __pOwner->Invalidate(true);
737                 if (__pTextEvent)
738                 {
739                         IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(textEventStatus);
740                         if (pEventArg)
741                         {
742                                 __pTextEvent->Fire(*pEventArg);
743                         }
744                 }
745         }
746
747         return;
748 }
749
750 void
751 _Keypad::OnKeypadWillOpen(void)
752 {
753         return;
754 }
755
756 void
757 _Keypad::OnKeypadOpened(void)
758 {
759         if (__pChildEdit->IsUsbKeyboardConnected())
760         {
761                 __isPredictionWindowOpendInUSBMode = true;
762         }
763
764         ChangeLayoutInternal();//usb off & bounded or usb on & prediction
765
766         return;
767 }
768
769 void
770 _Keypad::OnKeypadClosed(void)
771 {
772         ChangeLayoutInternal();
773
774         return;
775 }
776
777 void
778 _Keypad::OnKeypadBoundsChanged(void)
779 {
780         ChangeLayoutInternal();// predictive window show/hide
781
782         return;
783 }
784
785 void
786 _Keypad::OnKeypadActionPerformed(CoreKeypadAction keypadAction)
787 {
788         return;
789 }
790
791 void
792 _Keypad::OnChangeLayout(_ControlOrientation orientation)
793 {
794         if (__isInitialized)
795         {
796                 ChangeLayoutInternal();
797         }
798
799         return;
800 }
801
802 result
803 _Keypad::Dispose(void)
804 {
805         result r = E_SUCCESS;
806         if (__pFooter)
807         {
808                 DetachChild(*__pFooter);
809                 delete __pFooter;
810                 __pFooter = null;
811         }
812         if (__pChildEdit)
813         {
814                 __pChildEdit->HideKeypad();
815                 DetachChild(*__pChildEdit);
816                 delete __pChildEdit;
817                 __pChildEdit = null;
818         }
819         __pCallerEdit = null;
820
821         if (__pTextEvent)
822         {
823                 delete __pTextEvent;
824                 __pTextEvent = null;
825         }
826         return r;
827 }
828
829 } } } // Tizen::Ui::Controls