add patch
[framework/osp/web.git] / src / controls / FWebCtrl_InputPickerPopup.cpp
index 15eeaf7..0826358 100755 (executable)
 #include <FUiCtrlEditTime.h>
 #include <FUiCtrlLabel.h>
 #include <FUiIActionEventListener.h>
+#include <FUiKeyEventInfo.h>
 #include <FUiLayout.h>
 #include <FUiVerticalBoxLayout.h>
 #include <FWebCtrlAuthenticationChallenge.h>
-#include <FUiCtrl_PopupImpl.h>
-#include <FUi_ResourceManager.h>
 #include <FSys_SystemResource.h>
+#include <FUi_ResourceManager.h>
 #include "FWebCtrl_WebImpl.h"
 #include "FWebCtrl_InputPickerPopup.h"
 
 
 using namespace Tizen::Base;
 using namespace Tizen::Graphics;
-using namespace Tizen::Web::Controls;
-using namespace Tizen::Ui::Controls;
-using namespace Tizen::Ui;
 using namespace Tizen::Locales;
 using namespace Tizen::System;
+using namespace Tizen::Ui;
+using namespace Tizen::Ui::Controls;
 
 
 namespace Tizen { namespace Web { namespace Controls
@@ -64,6 +63,7 @@ _InputPickerPopup::_InputPickerPopup(void)
        , __pEditTime(null)
        , __pSelectionBtn(null)
        , __modal(0)
+       , __isModal(false)
        , __popupHeight(0)
        , __popupWidth(0)
        , __btnHeight(0)
@@ -74,11 +74,15 @@ _InputPickerPopup::_InputPickerPopup(void)
 
 _InputPickerPopup::~_InputPickerPopup(void)
 {
+       if (__isModal == true)
+       {
+               HidePopup();
+       }
 }
 
 
 result
-_InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
+_InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType, Tizen::Web::Controls::_WebImpl* pImpl)
 {
        result r = E_SUCCESS;
 
@@ -98,7 +102,7 @@ _InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
                r = Parse(strDate, inputDateTime);
        }
 
-       _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
+       _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
 
        GET_SHAPE_CONFIG(EDITDATE::WIDTH, orientation, dateWidth);
        GET_SHAPE_CONFIG(EDITDATE::HEIGHT, orientation, dateHeight);
@@ -107,6 +111,8 @@ _InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
        GET_SHAPE_CONFIG(MESSAGEBOX::MIN_HEIGHT, orientation, __popupHeight);
        GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __btnHeight);
 
+       __popupWidth -= 2*sideMargin;
+
        std::unique_ptr<EditDate> pEditDate(new (std::nothrow) EditDate());
        SysTryReturnResult(NID_WEB_CTRL, pEditDate.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
 
@@ -194,6 +200,8 @@ _InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
        r = AddButton(ID_BUTTON_INPUT_DATE_SELECTION);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       __pPopup->SetPropagatedKeyEventListener(this);
+       
        std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(__pPopup->GetLayoutN()));
        SysTryReturnResult(NID_WEB_CTRL, pLayout.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
 
@@ -217,7 +225,7 @@ _InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
 
 
 result
-_InputPickerPopup::Construct(const Color& color)
+_InputPickerPopup::Construct(const Color& color, Tizen::Web::Controls::_WebImpl* pImpl)
 {
        result r = E_SUCCESS;
 
@@ -240,6 +248,7 @@ _InputPickerPopup::Construct(const Color& color)
 
        pColorPicker->SetColor(color);
 
+       __pPopup->SetPropagatedKeyEventListener(this);
        r = __pPopup->AddControl(*pColorPicker);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -295,7 +304,7 @@ _InputPickerPopup::CreatePopup(void)
        std::unique_ptr<Popup> pPopup(new (std::nothrow) Popup());
        SysTryReturnResult(NID_WEB_CTRL, pPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
 
-       r = pPopup->Construct(layout, layout, true, Tizen::Graphics::Dimension(__popupWidth, __popupHeight));
+       r = pPopup->Construct(layout, layout, true, Dimension(__popupWidth, __popupHeight));
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        __pPopup = std::move(pPopup);
@@ -310,11 +319,11 @@ _InputPickerPopup::AddButton(_InputPickerButtonId buttonId)
        result r = E_SUCCESS;
 
        String buttonStr;
-       
-       Tizen::System::_SystemResource* pSysResource = Tizen::System::_SystemResource::GetInstance();
+
+       _SystemResource* pSysResource = _SystemResource::GetInstance();
        SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
 
-       buttonStr = pSysResource->GetString("sys_string", "IDS_COM_SK_OK");
+       buttonStr = pSysResource->GetString("sys_string", "IDS_TPLATFORM_BUTTON_OK");
 
        std::unique_ptr<Button> pSelectionBtn(new (std::nothrow) Button());
        SysTryReturnResult(NID_WEB_CTRL, pSelectionBtn.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
@@ -474,6 +483,8 @@ _InputPickerPopup::ShowPopup(void)
        r = __pPopup->SetShowState(true);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       __isModal = true;
+
        r = __pPopup->DoModal(__modal);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -489,12 +500,48 @@ _InputPickerPopup::HidePopup(void)
        r = __pPopup->SetShowState(false);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       __isModal = false;
+
        r = __pPopup->EndModal(__modal);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
 
+bool
+_InputPickerPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_InputPickerPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
+       {
+               HidePopup();
+       }
+
+       return false;
+}
+
+bool
+_InputPickerPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_InputPickerPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_InputPickerPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
 
 String
 _InputPickerPopup::GetDate(void) const
@@ -513,12 +560,6 @@ _InputPickerPopup::GetColor(void) const
 result
 _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
 {
-       result r = E_SUCCESS;
-
-       wchar_t* pMchar = (wchar_t*) strDateTime.GetPointer();
-       wchar_t* pTmp = (wchar_t*) malloc(sizeof(wchar_t) * 10);
-       SysTryReturnResult(NID_WEB_CTRL, pTmp, E_OUT_OF_MEMORY, "Memory allocation failed.");
-
        std::unique_ptr<DateTimeFormatter> pDateFormatter(DateTimeFormatter::CreateDateFormatterN(DATE_TIME_STYLE_DEFAULT));
        SysTryReturn(NID_WEB_CTRL, pDateFormatter.get(), GetLastResult(), GetLastResult(),  "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -529,9 +570,16 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
        int hour = 0;
        int minute = 0;
        int week = 0;
+
+       result r = E_SUCCESS;
+
        String formattedString = L"e";
        String dayno;
 
+       const wchar_t* pMchar = static_cast< const wchar_t* >(strDateTime.GetPointer());
+       wchar_t* pTmp = static_cast< wchar_t* >(malloc(sizeof(wchar_t) * 10));
+       SysTryReturnResult(NID_WEB_CTRL, pTmp, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
        switch (__inputType)
        {
        case EWK_INPUT_TYPE_TIME :                       //"HH:mm";
@@ -539,12 +587,12 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
                // hour
                wcsncpy(pTmp, pMchar, 2);
                pTmp[2] = L'\0';
-               hour = (int) wcstol(pTmp, null, 10);
+               hour = static_cast< int >(wcstol(pTmp, null, 10));
 
                // minute
                wcsncpy(pTmp, pMchar + 3, 2);
                pTmp[2] = L'\0';
-               minute = (int) wcstol(pTmp, null, 10);
+               minute = static_cast< int >(wcstol(pTmp, null, 10));
                dateTime.SetValue(1, 1, 1, hour,minute);
                break;
 
@@ -555,30 +603,30 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
                wcsncpy(pTmp, pMchar, 4);
                pTmp[4] = L'\0';
 
-               year = (int) wcstol(pTmp, null, 10);
+               year = static_cast< int >(wcstol(pTmp, null, 10));
 
                // month
                wcsncpy(pTmp, pMchar + 5, 2);
                pTmp[2] = L'\0';
 
-               month = (int) wcstol(pTmp, null, 10);
+               month = static_cast< int >(wcstol(pTmp, null, 10));
 
                // day
                wcsncpy(pTmp, pMchar + 8, 2);
                pTmp[2] = L'\0';
 
-               day = (int) wcstol(pTmp, null, 10);
+               day = static_cast< int >(wcstol(pTmp, null, 10));
 
                // hour
                wcsncpy(pTmp, pMchar + 11, 2);
                pTmp[2] = L'\0';
 
-               hour = (int) wcstol(pTmp, null, 10);
+               hour = static_cast< int >(wcstol(pTmp, null, 10));
 
                // minute
                wcsncpy(pTmp, pMchar + 14, 2);
                pTmp[2] = L'\0';
-               minute = (int) wcstol(pTmp, null, 10);
+               minute = static_cast< int >(wcstol(pTmp, null, 10));
                dateTime.SetValue(year, month, day, hour, minute);
                break;
 
@@ -588,12 +636,12 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
                wcsncpy(pTmp, pMchar, 4);
                pTmp[4] = L'\0';
 
-               year = (int) wcstol(pTmp, null, 10);
+               year = static_cast< int >(wcstol(pTmp, null, 10));
 
                // week
                wcsncpy(pTmp, pMchar + 6, 2);
                pTmp[2] = L'\0';
-               week = (int) wcstol(pTmp, null, 10);
+               week = static_cast< int >(wcstol(pTmp, null, 10));
 
                dateTime.SetValue(year,1,1);
                pDateFormatter->ApplyPattern(formattedString);
@@ -608,17 +656,17 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
                // year
                wcsncpy(pTmp, pMchar, 4);
                pTmp[4] = L'\0';
-               year = (int) wcstol(pTmp, null, 10);
+               year = static_cast< int >(wcstol(pTmp, null, 10));
 
                // month
                wcsncpy(pTmp, pMchar + 5, 2);
                pTmp[2] = L'\0';
-               month = (int) wcstol(pTmp, null, 10);
+               month = static_cast< int >(wcstol(pTmp, null, 10));
 
                // day
                wcsncpy(pTmp, pMchar + 8, 2);
                pTmp[2] = L'\0';
-               day = (int) wcstol(pTmp, null, 10);
+               day = static_cast< int >(wcstol(pTmp, null, 10));
 
                dateTime.SetValue(year, month, day);
                break;
@@ -628,12 +676,12 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
                // year
                wcsncpy(pTmp, pMchar, 4);
                pTmp[4] = L'\0';
-               year = (int) wcstol(pTmp, null, 10);
+               year = static_cast< int >(wcstol(pTmp, null, 10));
 
                // month
                wcsncpy(pTmp, pMchar + 5, 2);
                pTmp[2] = L'\0';
-               month = (int) wcstol(pTmp, null, 10);
+               month = static_cast< int >(wcstol(pTmp, null, 10));
 
                dateTime.SetValue(year, month, 1);
                break;
@@ -641,15 +689,11 @@ _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
        default :
                r = E_UNSUPPORTED_OPTION;
                SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
-               return r;
        }
 
-       if (pTmp)
-       {
-               free(pTmp);
-       }
+       free(pTmp);
 
-       return E_SUCCESS;
+       return r;
 }