add keycode for H/W Back and B/T Keyboard
[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         : __isInitialized(false)
64         , __isSingleLineEnabled(false)
65         , __pIndicator(null)
66         , __pCallerEdit(null)
67         , __pChildEdit(null)
68         , __pFooter(null)
69         , __text()
70         , __pTextEvent(null)
71         , __isCommandButtonPressed(false)
72         , __isPredictionWindowOpendInUSBMode(false)
73 {
74         _AccessibilityContainer* pAccessibilityContainer = GetAccessibilityContainer();
75         if(pAccessibilityContainer)
76         {
77                 pAccessibilityContainer->Activate(true);
78         }
79
80         _ControlManager::GetInstance()->SetClipboardOwner(this);
81 }
82
83 _Keypad::~_Keypad(void)
84 {
85         _ControlManager::GetInstance()->SetClipboardOwner(null);
86
87         Dispose();
88 }
89
90 _Keypad*
91 _Keypad::CreateKeypadN(void)
92 {
93         ClearLastResult();
94
95         Dimension screenSize = _ControlManager::GetInstance()->GetScreenSize();
96
97         Rectangle portBounds(0, 0, screenSize.width, screenSize.height);
98         Rectangle landBounds(0, 0, screenSize.width, screenSize.height);
99         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
100
101         _Keypad* pKeypad = new (std::nothrow) _Keypad;
102         result r = GetLastResult();
103         SysTryCatch(NID_UI_CTRL, pKeypad, , r, "[%s] Propagating.", GetErrorMessage(r));
104         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
105
106         r = pKeypad->CreateRootVisualElement(_WINDOW_TYPE_SUB);
107
108         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
109
110         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 0, portBounds);
111         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 180, portBounds);
112         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 90, landBounds);
113         pEcoreEvas->SetWindowRotationBounds(*pKeypad, 270, landBounds);
114
115         pKeypad->AcquireHandle();
116
117         return pKeypad;
118
119 CATCH:
120         delete pKeypad;
121
122         return null;
123 }
124
125 result
126 _Keypad::Initialize(int editStyle, _KeypadStyleInfo keypadStyleInfo, int limitLength, _Edit* pCallerEdit)
127 {
128         result r = E_SUCCESS;
129         bool UsbKeyboardConnected = false;
130
131         _ControlManager* pControlManager = _ControlManager::GetInstance();
132         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
133
134         if (GetOwner() == null)
135         {
136                 _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
137                 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM,
138                                         E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
139
140                 _Form* pForm = pFrame->GetCurrentForm();
141
142                 if (pForm)
143                 {
144                         SetOwner(pForm);
145                 }
146                 else
147                 {
148                         SetOwner(pFrame);
149                 }
150         }
151
152         __pFooter = CreateFooter();
153
154         if (!__pFooter)
155         {
156                 SysTryReturnResult(NID_UI_CTRL, __pFooter, GetLastResult(), "Unable to create Footer");
157         }
158
159         if (pCallerEdit)
160         {
161                 __pCallerEdit = pCallerEdit;
162         }
163         else
164         {
165                 __pCallerEdit = null;
166         }
167
168         if ( __pChildEdit == null)
169         {
170                 __pChildEdit = _Edit::CreateEditN();
171                 SysTryCatch(NID_UI_CTRL, __pChildEdit, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Unable to create Edit");
172
173                 String doneText;
174                 String cancelText;
175                 _AccessibilityContainer* pAccessibilityContainer = null;
176
177                 GET_STRING_CONFIG(IDS_COM_SK_DONE, doneText);
178                 GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
179
180                 __pChildEdit->SetFullScreenKeypadEdit(true);
181
182                 r = __pChildEdit->Initialize(editStyle, INPUT_STYLE_OVERLAY, limitLength);
183                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
184
185                 __pChildEdit->SetTextPredictionEnabled(keypadStyleInfo.textPredictionEnabled);
186                 __pChildEdit->SetKeypadNormalNumberStyle(keypadStyleInfo.isNormalNumberStyle);
187                 __pChildEdit->SetKeypadStyle(keypadStyleInfo.keypadStyle);
188                 if (!keypadStyleInfo.enterActionEnabled)//EditField Style
189                 {
190                         __pChildEdit->SetKeypadActionEnabled(false);
191                 }
192
193                 __pChildEdit->SetLowerCaseModeEnabled(keypadStyleInfo.isLowerCaseModeEnabled);
194
195                 r = __pChildEdit->SetKeypadCommandButtonVisible(false);
196                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
197
198                 __pChildEdit->AddKeypadEventListener(*this);
199
200                 r = AttachChild(*__pChildEdit);
201                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
202
203                 pAccessibilityContainer = GetAccessibilityContainer();
204                 if (pAccessibilityContainer)
205                 {
206                         _AccessibilityContainer* pAccessibilityEdit = __pChildEdit->GetAccessibilityContainer();
207                         if (pAccessibilityEdit)
208                         {
209                                 pAccessibilityContainer->AddChildContainer(*pAccessibilityEdit);
210                         }
211                 }
212         }
213
214         SetClipChildrenEnabled(false);
215
216         if (!__pIndicator)
217         {
218                 __pIndicator = _Indicator::CreateIndicator();
219                 SysTryCatch(NID_UI_CTRL, __pIndicator, , GetLastResult(), "Unable to create Indicator");
220
221                 _VisualElement* pKeypadVisualElement = GetVisualElement();
222                 pKeypadVisualElement->AttachChild(*__pIndicator);
223
224                 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*__pIndicator);
225                 r = pImpl->SetZOrderGroup(_ControlVisualElement::Z_ORDER_GROUP_CONTROL + 4);
226
227                 float indicatorwidth = 0.0f;
228                 float indicatorheight = 0.0f;
229
230                 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
231                 {
232                         indicatorwidth = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF().width;
233                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
234                 }
235                 else
236                 {
237                         indicatorwidth = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF().height;
238                         GET_SHAPE_CONFIG(FORM::INDICATOR_MINIMIZE_HEIGHT, GetOrientation(), indicatorheight);
239                 }
240
241                 __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, indicatorwidth, indicatorheight));
242                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
243         }
244
245         UsbKeyboardConnected = __pChildEdit->IsUsbKeyboardConnected();
246
247         r = ChangeLayoutInternal(LAYOUT_CHANGE_NONE);
248         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
249
250         __pChildEdit->SetVisibleState(true);
251
252         __isInitialized = true;
253
254         r = _SettingInfoImpl::AddSettingEventListenerForInternal(*this);
255         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
256
257         return r;
258
259 CATCH:
260         Dispose();
261         return r;
262 }
263
264 result
265 _Keypad::Dispose(void)
266 {
267         result r = E_SUCCESS;
268         if (__pFooter)
269         {
270                 DetachChild(*__pFooter);
271                 delete __pFooter;
272                 __pFooter = null;
273         }
274         if (__pChildEdit)
275         {
276                 DetachChild(*__pChildEdit);
277                 delete __pChildEdit;
278                 __pChildEdit = null;
279         }
280         __pCallerEdit = null;
281
282         if (__pTextEvent)
283         {
284                 delete __pTextEvent;
285                 __pTextEvent = null;
286         }
287
288         if (__pIndicator)
289         {
290                 _VisualElement* pKeypadVisualElement = GetVisualElement();
291                 pKeypadVisualElement->DetachChild(*__pIndicator);
292                 delete __pIndicator;
293                 __pIndicator = null;
294         }
295
296         _SettingInfoImpl::RemoveSettingEventListenerForInternal(*this);
297
298         return r;
299 }
300
301 _Toolbar*
302 _Keypad::CreateFooter(void)
303 {
304         result r = E_SUCCESS;
305
306         _Toolbar* pFooter = null;
307
308         if (!__pFooter)
309         {
310                 _ControlManager* pControlManager = _ControlManager::GetInstance();
311                 SysTryReturn(NID_UI_CTRL, pControlManager, null, E_SYSTEM, "Fail to get ControlManager instance");
312
313                 _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
314                 SysTryReturn(NID_UI_CTRL, pFrame, null, E_SYSTEM, "This instance is not constructed.");
315
316                 String doneText;
317
318                 FloatRectangle bounds(0.0f,0.0f,0.0f,0.0f);
319
320                 FloatDimension screenSize = pControlManager->GetScreenSizeF();
321
322                 pFooter = _Toolbar::CreateToolbarN(false);
323                 SysTryReturn(NID_UI_CTRL, pFooter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create instance.");
324
325                 r = pFooter->Construct();
326                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
327
328                 r = pFooter->SetStyle(TOOLBAR_TEXT);
329                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
330
331                 pFooter->SetResizable(true);
332                 pFooter->SetMovable(true);
333
334                 _ControlOrientation orientation = GetOrientation();
335
336                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
337                 {
338                         bounds.width = screenSize.width;
339                 }
340                 else
341                 {
342                         bounds.width = screenSize.height;
343                 }
344
345                 float height = 0.0f;
346                 GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, height);
347                 bounds.height = height;
348
349                 r = pFooter->SetBounds(bounds);
350                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
351
352                 pFooter->SetResizable(false);
353                 pFooter->SetMovable(false);
354
355                 GET_STRING_CONFIG(IDS_COM_SK_DONE, doneText);
356
357                 r = pFooter->AddItem(CreateButtonItemN(COMMAND_DONE_BUTTON_ID, doneText));
358                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
359
360                 pFooter->AddActionEventListener(*this);
361
362                 bool isHWBackButtonExist = false;
363
364                 Tizen::System::SystemInfo::GetValue(L"http://tizen.org/feature/input.keys.back", isHWBackButtonExist);
365
366                 if(!isHWBackButtonExist)
367                 {
368                         pFooter->SetBackEventListener(*this, FOOTER_BACK_BUTTON_ID);
369                         pFooter->SetButton(BACK_BUTTON, CreateFooterBackButton(pFooter));
370                 }
371
372                 r = AttachChild(*pFooter);
373                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
374
375                 return pFooter;
376
377         }
378         else
379         {
380                 return __pFooter;
381         }
382
383 CATCH:
384         delete pFooter;
385         return null;
386 }
387
388 _Button*
389 _Keypad::CreateFooterBackButton(_Toolbar* pFooter)
390 {
391         _Button* pButton = _Button::CreateButtonN();
392
393         float buttonHeight = 0.0f;
394         float buttonWidth = 0.0f;
395         float iconSize = 0.0f;
396
397         GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_HEIGHT, pFooter->GetOrientation(), buttonHeight);
398         GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_WIDTH, pFooter->GetOrientation(), buttonWidth);
399         GET_SHAPE_CONFIG(FOOTER::BUTTON_ITEM_ICON_SIZE, pFooter->GetOrientation(), iconSize);
400
401         pButton->SetSize(FloatDimension(buttonWidth, buttonHeight));
402
403         Bitmap* pBackgroundNormalBitmap = null;
404         Bitmap* pBackgroundPressedBitmap = null;
405         Bitmap* pColorReplacedBitmap = null;
406         Bitmap* pBackIconNormalBitmap = null;
407         Bitmap* pBackIconNormalEffectBitmap = null;
408
409         GET_BITMAP_CONFIG_N(FOOTER::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundNormalBitmap);
410         GET_BITMAP_CONFIG_N(FOOTER::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundPressedBitmap);
411         GET_BITMAP_CONFIG_N(FOOTER::BACK_ICON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackIconNormalBitmap);
412         GET_BITMAP_CONFIG_N(FOOTER::BACK_ICON_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackIconNormalEffectBitmap);
413
414         bool themeBackNormalBitmap = IS_CUSTOM_BITMAP(FOOTER::BACK_ICON_NORMAL);
415         if (!themeBackNormalBitmap)
416         {
417                 GET_BITMAP_CONFIG_N(FOOTER::BACK_ICON_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackIconNormalEffectBitmap);
418         }
419
420         if (pBackgroundNormalBitmap)
421         {
422                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA),
423                                 pFooter->GetButtonColor(_BUTTON_STATUS_NORMAL));
424                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_NORMAL, *pColorReplacedBitmap);
425                 delete pColorReplacedBitmap;
426
427                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA),
428                                 pFooter->GetButtonColor(_BUTTON_STATUS_HIGHLIGHTED));
429                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_HIGHLIGHTED, *pColorReplacedBitmap);
430                 delete pColorReplacedBitmap;
431
432                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA),
433                                 pFooter->GetButtonColor(_BUTTON_STATUS_DISABLED));
434                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_DISABLED, *pColorReplacedBitmap);
435                 delete pColorReplacedBitmap;
436
437                 delete pBackgroundNormalBitmap;
438         }
439
440         if (pBackgroundPressedBitmap)
441         {
442                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundPressedBitmap, Color::GetColor(COLOR_ID_MAGENTA),
443                                 pFooter->GetButtonColor(_BUTTON_STATUS_PRESSED));
444                 pButton->SetBackgroundBitmap(_BUTTON_STATUS_PRESSED, *pColorReplacedBitmap);
445                 delete pColorReplacedBitmap;
446
447                 delete pBackgroundPressedBitmap;
448         }
449
450         if (pBackIconNormalBitmap)
451         {
452                 Color normalColor;
453                 Color pressedColor;
454                 Color disabledColor;
455
456                 GET_COLOR_CONFIG(FOOTER::BACK_ICON_NORMAL, normalColor);
457                 GET_COLOR_CONFIG(FOOTER::BACK_ICON_PRESSED, pressedColor);
458                 GET_COLOR_CONFIG(FOOTER::BACK_ICON_DISABLED, disabledColor);
459
460                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackIconNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalColor);
461                 if (pColorReplacedBitmap)
462                 {
463                         pColorReplacedBitmap->Scale(FloatDimension(iconSize, iconSize));
464
465                         pButton->SetBitmap(_BUTTON_STATUS_NORMAL, FloatPoint(0.0f, 0.0f), *pColorReplacedBitmap);
466
467                         delete pColorReplacedBitmap;
468                 }
469
470                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackIconNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
471                 if (pColorReplacedBitmap)
472                 {
473                         pColorReplacedBitmap->Scale(FloatDimension(iconSize, iconSize));
474
475                         pButton->SetBitmap(_BUTTON_STATUS_PRESSED, FloatPoint(0.0f, 0.0f), *pColorReplacedBitmap);
476                         delete pColorReplacedBitmap;
477                 }
478
479                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackIconNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), disabledColor);
480                 if (pColorReplacedBitmap)
481                 {
482                         pColorReplacedBitmap->Scale(FloatDimension(iconSize, iconSize));
483
484                         pButton->SetBitmap(_BUTTON_STATUS_DISABLED, FloatPoint(0.0f, 0.0f), *pColorReplacedBitmap);
485                         delete pColorReplacedBitmap;
486                 }
487
488                 delete pBackIconNormalBitmap;
489         }
490
491         if (pBackIconNormalEffectBitmap)
492         {
493                 pButton->SetEffectBitmap(_BUTTON_STATUS_NORMAL, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
494                 pButton->SetEffectBitmap(_BUTTON_STATUS_PRESSED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
495                 pButton->SetEffectBitmap(_BUTTON_STATUS_SELECTED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
496                 pButton->SetEffectBitmap(_BUTTON_STATUS_HIGHLIGHTED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
497                 pButton->SetEffectBitmap(_BUTTON_STATUS_DISABLED, FloatPoint(0.0f, 0.0f), *pBackIconNormalEffectBitmap);
498
499                 delete pBackIconNormalEffectBitmap;
500         }
501
502         return pButton;
503 }
504
505 _Button*
506 _Keypad::CreateButtonItemN(int actionId, const String& text)
507 {
508         result r = E_SUCCESS;
509         _Button* pButton = _Button::CreateButtonN();
510         SysTryReturn(NID_UI_CTRL, pButton, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create instance.");
511
512         r = pButton->SetActionId(actionId);
513         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
514
515         r = pButton->SetText(text);
516         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
517
518         return pButton;
519 CATCH:
520         delete pButton;
521
522         return null;
523 }
524
525 result
526 _Keypad::ChangeLayoutInternal(LayoutChangeState layoutChangeState)
527 {
528         result r = E_SUCCESS;
529         _ControlManager* pControlManager = _ControlManager::GetInstance();
530         SysTryReturnResult(NID_UI_CTRL, pControlManager, E_SYSTEM, "Failed to get root.");
531         FloatDimension screenSize = pControlManager->GetScreenSizeF();
532         _ControlOrientation orientation = GetOrientation();
533
534         _Frame* pFrame = dynamic_cast <_Frame*>(pControlManager->GetCurrentFrame());
535         SysTryReturn(NID_UI_CTRL, pFrame, null, E_SYSTEM, "This instance is not constructed.");
536
537         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
538         FloatRectangle keypadRect(0.0f, 0.0f, 0.0f, 0.0f);
539         float indicatorHeight = 0.0f;
540         float clipboardHeight = 0.0f;
541         bool isKeypadExist = false;
542         bool isClipboardExist = false;
543
544         if (__isInitialized == true)
545         {
546                 isKeypadExist = __pChildEdit->CheckKeypadExist(orientation);
547                 isClipboardExist = __pChildEdit->IsClipboardExist();
548         }
549
550         if ((isClipboardExist && layoutChangeState == LAYOUT_CHANGE_ROTATE))
551         {
552                 return E_SUCCESS;
553         }
554
555         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
556         {
557                 bounds.width = screenSize.width;
558                 bounds.height = screenSize.height;
559         }
560         else
561         {
562                 bounds.width = screenSize.height;
563                 bounds.height = screenSize.width;
564         }
565
566         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
567         {
568                 GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorHeight);
569         }
570         else
571         {
572                 GET_SHAPE_CONFIG(FORM::INDICATOR_MINIMIZE_HEIGHT, GetOrientation(), indicatorHeight);
573         }
574
575         SetResizable(true);
576         SetMovable(true);
577         r = SetBounds(bounds);
578         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
579         SetResizable(false);
580         SetMovable(false);
581
582         FloatRectangle editRect = bounds;
583
584         editRect.y = indicatorHeight;
585
586         float footerHeight = 0.0f;
587         GET_SHAPE_CONFIG(FOOTER::HEIGHT, orientation, footerHeight);
588
589         editRect.height -= indicatorHeight;
590         editRect.height -= footerHeight;
591
592         if ( isKeypadExist || isClipboardExist)
593         {
594                 if (isKeypadExist)
595                 {
596                         r = __pChildEdit->GetKeypadBounds(keypadRect);
597                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
598                 }
599
600                 if (isClipboardExist)
601                 {
602                         clipboardHeight = __pChildEdit->GetClipboardHeight();
603                 }
604
605                 if (clipboardHeight > keypadRect.height)
606                 {
607                         editRect.height -= clipboardHeight;
608                 }
609                 else
610                 {
611                         editRect.height -= keypadRect.height;
612                 }
613
614                 if (!__isPredictionWindowOpendInUSBMode)
615                 {
616                         __pFooter->SetHideButton(true);
617                 }
618         }
619         else
620         {
621                 __pFooter->SetHideButton(false);
622         }
623
624         r = __pChildEdit->SetBounds(editRect);
625         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS,  r, r, "[%s] Propagating.", GetErrorMessage(r));
626
627         FloatRectangle footerBounds(0.0f, 0.0f, 0.0f, 0.0f);
628
629         footerBounds.y = editRect.height + indicatorHeight;
630         footerBounds.width = editRect.width;
631         footerBounds.height = footerHeight;
632
633         __pFooter->SetResizable(true);
634         __pFooter->SetMovable(true);
635
636         __pFooter->SetBounds(footerBounds);
637
638         __pFooter->SetResizable(false);
639         __pFooter->SetMovable(false);
640
641         SysLog(NID_UI_CTRL, "[FULLEDIT] ChangeLayoutInternal Draw FullScreen window- Footer position(%f, %f, %f, %f)", footerBounds.x, footerBounds.y, footerBounds.width, footerBounds.height);
642         Invalidate(true);
643
644         return r;
645 }
646
647 result
648 _Keypad::OnAttachedToMainTree(void)
649 {
650         result r = E_SUCCESS;
651
652         GetEcoreEvasMgr()->GetEcoreEvas()->SetOwner(*this, *GetOwner());//set owner to EcoreEvas for orientation set.
653
654         r = __pChildEdit->SetText(__text);
655         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
656
657         if (__pIndicator)
658         {
659                 __pIndicator->OnAttachedToMainTree();
660                 __pIndicator->AddIndicatorObject(this, GetRootWindow());
661                 __pIndicator->SetIndicatorShowState(true);
662         }
663
664         Invalidate(true);
665
666         return r;
667 }
668
669 result
670 _Keypad::OnDetachingFromMainTree(void)
671 {
672         if (__pIndicator)
673         {
674                 __pIndicator->DeleteIndicatorObject();
675         }
676
677         if (__pCallerEdit && !__pCallerEdit->IsInputEventEnabled())
678         {
679                 __pCallerEdit->UnlockInputEvent();
680         }
681
682         return _Window::OnDetachingFromMainTree();
683 }
684
685 void
686 _Keypad::OnNativeWindowActivated(void)
687 {
688         __pChildEdit->SetFocused();
689
690         return;
691 }
692
693 bool
694 _Keypad::IsRotationSynchronized(void) const
695 {
696         return true;
697 }
698
699 void
700 _Keypad::OnDraw(void)
701 {
702         Canvas* pCanvas = GetCanvasN();
703         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
704
705         Color backgroundColor;
706         GET_COLOR_CONFIG(EDIT::BG_NORMAL, backgroundColor);
707
708         pCanvas->SetBackgroundColor(backgroundColor);
709         pCanvas->Clear();
710         delete pCanvas;
711
712         return;
713 }
714
715 result
716 _Keypad::SetSingleLineEnabled(bool enabled)
717 {
718         SetProperty("singleLineEnabled", Variant(enabled));
719
720         return E_SUCCESS;
721 }
722
723 bool
724 _Keypad::IsSingleLineEnabled(void) const
725 {
726         Variant enabled = GetProperty("singleLineEnabled");
727
728         return enabled.ToBool();
729 }
730
731 result
732 _Keypad::SetPropertySingleLineEnabled(const Variant& enabled)
733 {
734         __isSingleLineEnabled = enabled.ToBool();
735
736         return E_SUCCESS;
737 }
738
739 Variant
740 _Keypad::GetPropertySingleLineEnabled(void) const
741 {
742         return Variant(__isSingleLineEnabled);
743 }
744
745 String
746 _Keypad::GetText(void) const
747 {
748         Variant text = GetProperty("text");
749
750         return text.ToString();
751 }
752
753 void
754 _Keypad::SetText(const String& text)
755 {
756         SetProperty("text", Variant(text));
757
758         return;
759 }
760
761 result
762 _Keypad::SetPropertyText(const Variant& text)
763 {
764         __text = text.ToString();
765
766         return E_SUCCESS;
767 }
768
769 Variant
770 _Keypad::GetPropertyText(void) const
771 {
772         return Variant(__text);
773 }
774
775 result
776 _Keypad::AddTextEventListener(const _ITextEventListener& listener)
777 {
778         if (__pTextEvent == null)
779         {
780                 __pTextEvent = _TextEvent::CreateInstanceN(*this);
781                 SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.\n");
782         }
783
784         return __pTextEvent->AddListener(listener);
785 }
786
787 result
788 _Keypad::RemoveTextEventListener(const _ITextEventListener& listener)
789 {
790         SysTryReturn(NID_UI_CTRL, __pTextEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance isn't constructed.");
791         __pTextEvent->RemoveListener(listener);
792
793         return E_SUCCESS;
794 }
795
796 void
797 _Keypad::SetEditTextFilter(IEditTextFilter* pFilter)
798 {
799         if (__pChildEdit)
800         {
801                 __pChildEdit->SetEditTextFilter(pFilter);
802         }
803
804         return;
805 }
806
807 void
808 _Keypad::SendOpaqueCommand (const Tizen::Base::String& command)
809 {
810         if (__pChildEdit)
811         {
812                 __pChildEdit->SendOpaqueCommand(command);
813         }
814
815         return;
816 }
817
818 bool
819 _Keypad::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
820 {
821         if (keyInfo.GetKeyCode() == _KEY_ESC || keyInfo.GetKeyCode() == _KEY_BACK)
822         {
823                 OnActionPerformed(source, FOOTER_BACK_BUTTON_ID);
824         }
825
826         return true;
827 }
828
829 void
830 _Keypad::OnActionPerformed(const _Control& source, int actionId)
831 {
832         bool isReCreationLock = false;
833         if ((actionId != COMMAND_DONE_BUTTON_ID) && (actionId != FOOTER_BACK_BUTTON_ID))
834         {
835                 return;
836         }
837
838         if (actionId == FOOTER_BACK_BUTTON_ID)
839         {
840                 if (__isPredictionWindowOpendInUSBMode == false)
841                 {
842                         if (__pChildEdit->IsKeypadExist() && __pChildEdit->IsClipboardExist())
843                         {
844                                 _SystemUtilImpl::GenerateKeyEvent(KEY_EVENT_TYPE_PRESSED, _KEY_BACK);
845                                 _SystemUtilImpl::GenerateKeyEvent(KEY_EVENT_TYPE_RELEASED, _KEY_BACK);
846                                 _SystemUtilImpl::SendKeyStopMessage();
847                                 return;
848                         }
849
850                         if (__pChildEdit->IsKeypadExist())
851                         {
852                                 _SystemUtilImpl::GenerateKeyEvent(KEY_EVENT_TYPE_PRESSED, _KEY_BACK);
853                                 _SystemUtilImpl::GenerateKeyEvent(KEY_EVENT_TYPE_RELEASED, _KEY_BACK);
854                                 return;
855                         }
856
857                         if (__pChildEdit->IsClipboardExist())
858                         {
859                                 _SystemUtilImpl::SendKeyStopMessage();
860                                 return;
861                         }
862                 }
863         }
864
865         __pChildEdit->HideKeypad();
866
867         if (__pCallerEdit)
868         {
869                 __pCallerEdit->SetKeypadEnabled(false);
870                 isReCreationLock = true;
871         }
872         Close();
873         if (isReCreationLock)
874         {
875                 __pCallerEdit->SetKeypadEnabled(true);
876         }
877
878         CoreTextEventStatus textEventStatus = CORE_TEXT_EVENT_CHANGED;
879         if (actionId == COMMAND_DONE_BUTTON_ID)
880         {
881                 __text = __pChildEdit->GetText();
882                 textEventStatus = CORE_TEXT_EVENT_CHANGED;
883         }
884         else
885         {
886                 textEventStatus = CORE_TEXT_EVENT_CANCELED;
887         }
888
889         __isCommandButtonPressed = true;
890
891         if (__pCallerEdit)
892         {
893                 __pCallerEdit->SetText(__text);
894                 _Control* pParent = __pCallerEdit->GetParent();
895                 if (pParent)
896                 {
897                         pParent->Invalidate(true);
898                 }
899
900                 __pCallerEdit->SendTextEvent(textEventStatus);
901         }
902         else
903         {
904                 GetOwner()->Invalidate(true);
905                 if (__pTextEvent)
906                 {
907                         IEventArg* pEventArg = _TextEvent::CreateTextEventArgN(textEventStatus);
908                         if (pEventArg)
909                         {
910                                 __pTextEvent->Fire(*pEventArg);
911                         }
912                 }
913         }
914
915         return;
916 }
917
918 void
919 _Keypad::OnKeypadWillOpen(void)
920 {
921         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadWillOpen");
922         return;
923 }
924
925 void
926 _Keypad::OnKeypadOpened(void)
927 {
928         if (__pChildEdit->IsUsbKeyboardConnected())
929         {
930                 __isPredictionWindowOpendInUSBMode = true;
931         }
932
933         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadOpened");
934
935         ChangeLayoutInternal(LAYOUT_CHANGE_KEYPAD_SHOW);//usb off & bounded or usb on & prediction
936
937         return;
938 }
939
940 void
941 _Keypad::OnKeypadClosed(void)
942 {
943         __isPredictionWindowOpendInUSBMode = false;
944
945         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadClosed");
946
947         ChangeLayoutInternal(LAYOUT_CHANGE_KEYPAD_HIDE);
948
949         return;
950 }
951
952 void
953 _Keypad::OnKeypadBoundsChanged(void)
954 {
955         SysLog(NID_UI_CTRL, "[FULLEDIT] OnKeypadBoundsChanged");
956
957         ChangeLayoutInternal(LAYOUT_CHANGE_KEYPAD_BOUNDS_CHANGED);// predictive window show/hide
958
959         return;
960 }
961
962 void
963 _Keypad::OnKeypadActionPerformed(CoreKeypadAction keypadAction)
964 {
965         return;
966 }
967
968 void
969 _Keypad::OnChangeLayout(_ControlOrientation orientation)
970 {
971         float indicatorheight = 0.0f;
972
973         const FloatDimension portraitSize = _ControlManager::GetInstance()->_ControlManager::GetScreenSizeF();
974         const FloatDimension landscapeSize = FloatDimension(portraitSize.height, portraitSize.width);
975
976         if (__pIndicator)
977         {
978                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
979                 {
980                         GET_SHAPE_CONFIG(FORM::INDICATOR_HEIGHT, GetOrientation(), indicatorheight);
981                         __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, portraitSize.width, indicatorheight));
982                 }
983                 else
984                 {
985                         GET_SHAPE_CONFIG(FORM::INDICATOR_MINIMIZE_HEIGHT, GetOrientation(), indicatorheight);
986                         __pIndicator->SetBounds(FloatRectangle(0.0f, 0.0f, landscapeSize.width, indicatorheight));
987                 }
988
989                 __pIndicator->OnChangeLayout(orientation);
990         }
991
992         if (__isInitialized)
993         {
994                 ChangeLayoutInternal(LAYOUT_CHANGE_ROTATE);
995         }
996
997         return;
998 }
999
1000 void
1001 _Keypad::OnSettingChanged(String& key)
1002 {
1003         const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1004         if (key == LOCALE_LANGUAGE)
1005         {
1006                 if (__pFooter)
1007                 {
1008                         _Button* pButton = __pFooter->GetItem(0);
1009                         if (pButton)
1010                         {
1011                                 String doneText;
1012                                 GET_STRING_CONFIG(IDS_COM_SK_DONE, doneText);
1013                                 pButton->SetText(doneText);
1014                         }
1015                 }
1016         }
1017 }
1018
1019 bool
1020 _Keypad::IsLayoutChangable(void) const
1021 {
1022         return true;
1023 }
1024
1025 } } } // Tizen::Ui::Controls